public override Response Post(IDictionary<string, string> form, string sessionId = null) { ValidationHelper vh = new ValidationHelper(); IDictionary<string, string> errors = new Dictionary<string, string>(); if (!vh.LikeName(form["name"])) { errors.Add("name", "Invalid name!"); } if (!vh.LikeName(form["surname"])) { errors.Add("surname", "Invalid surname!"); } if (!vh.LikePhoneNumber(form["phone"])) { errors.Add("phone", "Invalid phone!"); } if (!vh.LikeAddress(form["address"])) { errors.Add("address", "Invalid address!"); } if(errors.Count == 0) { try { Client client = new Client(Guid.NewGuid(), form["name"], form["surname"], form["address"], form["phone"]); IClientService cs =serviceFactory.CreateClientService(); cs.Add(client); return new Response("", TypeOfAnswer.Redirection, "ClientsList"); } catch (Exception) { return new Response("", TypeOfAnswer.ServerError, ""); } } else { return this.Get(form, sessionId, errors); } }
public override Response Post(IDictionary<string, string> form, string sessionId = null) { Response response; try { IClientService cs = serviceFactory.CreateClientService(); Guid id = new Guid(form["id"]); Client client = new Client(id, form["name"], form["surname"], form["address"], form["phone"]); cs.Update(client); } catch(Exception ex) { Console.WriteLine(ex.Message); response = new Response("", TypeOfAnswer.ServerError, ""); return response; } response = new Response("", TypeOfAnswer.Redirection, "ClientsList"); return response; }