Example #1
0
        public override Response Post(IDictionary<string, string> form, string sessionId = null)
        {
            Response response;
            try
            {
                Dictionary<string, string> errors = new Dictionary<string, string>();
                //ManagerService ms = new ManagerService("manager.txt");
                IManagerService ms = serviceFactory.CreateManagerService();
                Manager manager = null;

                string value = ConfigurationManager.AppSettings["Admin"];
                Guid guid = new Guid("c32f3d67-26da-4cba-9595-8a9f0efa0e5b");

                if (form["password"] == value)
                {
                    manager = new Manager(guid, "admin", "admin", (WorkExperience)1, "", "911", "admin", "admin");
                }
                else
                {
                    manager = ((SQLManagerService)ms).GetElementByLogin(form["login"]);
                }

                if (manager == null)
                {
                    errors.Add("login", "User with such login does not exist!");
                    response = this.Get(form, sessionId, errors);
                }
                else if (manager.Password != form["password"])
                {
                    errors.Add("password", "Password is wrong!");
                    response = this.Get(form, sessionId, errors);
                }
                else
                {
                    response = new Response("", TypeOfAnswer.Redirection, "Index");

                        if (sessionId == null)
                        sessionId = Guid.NewGuid().ToString();

                    Session.Instance.RegisterSessions[sessionId].SetUser(manager.Id.ToString(), manager.Name, manager.Surname);

                    response.SessionId = sessionId;
                }
            }
            catch(Exception ex)
            {
                response = new Response("", TypeOfAnswer.ServerError, "");
                Console.WriteLine(ex.Message);
                return response;
            }

            return response;
        }
        public override Response Post(IDictionary<string, string> form, string sessionId = null)
        {
            ValidationHelper vh = new ValidationHelper();
            Dictionary<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.LikeAddress(form["address"]))
            {
                errors.Add("address", "Invalid address!");
            }
            if (!vh.LikePhoneNumber(form["phone"]))
            {
                errors.Add("phone", "Invalid phone!");
            }
            if (!vh.LikeAddress(form["login"]))
            {
                errors.Add("login", "Invalid login!");
            }
            if (!vh.LikeAddress(form["password"]))
            {
                errors.Add("password", "Invalid password!");
            }

            if (errors.Count == 0)
            {

                try
                {
                    Manager manager = new Manager(Guid.NewGuid(), form["name"], form["surname"], (WorkExperience)Convert.ToInt32(form["experience"]), form["address"], form["phone"], form["login"], form["password"]);
                    IManagerService sms = serviceFactory.CreateManagerService();
                   // manager.Work = (StageExperience.WorkExperience)Convert.ToInt32(form["experience"]);
                    sms.Add(manager);
                    return new Response("", TypeOfAnswer.Redirection, "ManagersList");
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message + "class  CreateManager  method POST");
                    return new Response("", TypeOfAnswer.ServerError, "");
                }
            }
            else
            {
                return this.Get(form, sessionId, errors);
            }
        }