NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

//
// ViewController.swift
// DiaryApp
//
// Created by Can Yüksel on 15.04.2017.
// Copyright © 2017 Can Yüksel. All rights reserved.
//

import UIKit
//import "ResultStatus"

class ViewController: UIViewController {

@IBOutlet var txtNote: UITextView!
@IBOutlet var lblUserName: UILabel!
var currentDayDiary = 0;
var CurrentUser = User();

@IBOutlet var denemetxt: UITextField!
@IBOutlet var btnSave: UIButton!

override func viewDidLoad() {
super.viewDidLoad()
self.txtNote.text = "CAN USTA";

}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
login()
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
func setCurrentUser(user : User){
self.CurrentUser = user;
self.lblUserName.text = "Hoşgeldiniz, " + user.FirstName + " " + user.LastName
/*
var request = URLRequest(url: URL(string:"http://diary.sshalkali.com.tr/Service.svc/GetCurrentDateDiary")!)
request.httpMethod = "GET"

let session = URLSession.shared
session.dataTask(with: request){
(data,response,error) -> Void in
guard let data = data, error == nil else {
print(error?.localizedDescription ?? "")
print(error.debugDescription)
return
}
do{

let result = ResultStatus()
let json = try JSONSerialization.jsonObject(with: data, options: []) as! [String:Any]
result.Status = json["Status"] as! Bool

if !result.Status
{
result.Messages = (json["Message"] as? String)!
let alert = UIAlertController(title: "HATA !", message: result.Messages, preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Tamam", style: UIAlertActionStyle.default, handler: { (action: UIAlertAction!) in
self.login()
}))
self.present(alert, animated: true, completion: nil)
}
else{
if(json["Article"] != nil){
let diaryJson = json["Article"] as! [String:Any]
let thisDayNote = diaryJson["Note"] as! String
self.currentDayDiary = diaryJson["Id"] as! Int;
self.txtNote.text = thisDayNote;
}
}
}catch let parseErroras as Error {
print("Error (parseErroras.localizedDescription)")
}

}.resume()
*/

}
@IBAction func btnSaveClick(_ sender: Any) {

let note = self.txtNote.text;
if((note?.characters.count)! > 0){
do{

var request = URLRequest(url: URL(string:"http://diary.sshalkali.com.tr/Service.svc/GetCurrentDateDiary")!)
request.timeoutInterval = 30;
request.httpMethod = "POST";
let data: [String : AnyObject] = [
"Id" : self.currentDayDiary as AnyObject,
"UserId" : self.CurrentUser.Id as AnyObject,
"Note" : note! as AnyObject
];
//request.httpBody = data;

var operation = OperationQueue();
NSURLConnection.sendAsynchronousRequest(request, queue: operation, completionHandler: {
(data,response ,error) -> Void in
guard let data = data, error == nil else {
print(error?.localizedDescription ?? "")
print(error.debugDescription)
self.login()
return
}




})
}
catch let ex{
print(ex.localizedDescription)
}
}

}
func login(){
let refreshAlert = UIAlertController(title: "Giriş", message: "Lütfen Giriş Yapın.", preferredStyle: UIAlertControllerStyle.alert)

refreshAlert.addTextField()
refreshAlert.addTextField()
let mailText = refreshAlert.textFields?[0]
if(mailText != nil)
{
mailText?.placeholder="Mail";
mailText?.keyboardType = UIKeyboardType.emailAddress;
}

let passText = refreshAlert.textFields?[1]

if(passText != nil){
passText?.placeholder="Şifre";
passText?.isSecureTextEntry = true;
}

refreshAlert.addAction(UIAlertAction(title: "Tamam", style: .default, handler: { (action: UIAlertAction!) in
let mail = refreshAlert.textFields?[0].text ?? "";
let pass = refreshAlert.textFields?[1].text ?? "";
if(mail != "" && pass != ""){
var request = URLRequest(url: URL(string: "http://diary.sshalkali.com.tr/Service.svc/Login/" + mail + "/" + pass)!)
request.httpMethod = "GET"
let session = URLSession.shared

session.dataTask(with: request) {(data,response ,error) -> Void in
guard let data = data, error == nil else {
print(error?.localizedDescription ?? "")
print(error.debugDescription)
self.login()
return
}

if let httpStatus = response as? HTTPURLResponse, httpStatus.statusCode != 200 {
print("statusCode should be 200, but is (httpStatus.statusCode)")
print("response = (response)")
self.login()
}

do{

let result = ResultStatus()
let json = try JSONSerialization.jsonObject(with: data, options: []) as! [String:Any]
result.Status = json["Status"] as! Bool

if !result.Status
{
result.Messages = (json["Message"] as? String)!
let alert = UIAlertController(title: "HATA !", message: result.Messages, preferredStyle: UIAlertControllerStyle.alert)
alert.addAction(UIAlertAction(title: "Tamam", style: UIAlertActionStyle.default, handler: { (action: UIAlertAction!) in
self.login()
}))
self.present(alert, animated: true, completion: nil)
}
else{
let user = User()
let userJson = json["Article"] as! [String:Any]
user.FirstName = userJson["FirstName"] as! String
user.LastName = userJson["LastName"] as! String
user.Id = userJson["Id"] as! Int
user.Mail = userJson["Mail"] as! String
user.Password = userJson["Password"] as! String
self.setCurrentUser(user: user);
}


}catch let parseError as NSError {
print("JSON Error (parseError.localizedDescription)")
}
}.resume()

}



}))

refreshAlert.addAction(UIAlertAction(title: "Vazgeç", style: .cancel, handler: { (action: UIAlertAction!) in
self.login()
}))

self.present(refreshAlert, animated: true, completion: nil)
}


}


     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.