public ActionResult LoggedIn(RecordEntityModel mod)
 {
     ;;
     HttpContext.Response.Cookies.Add(new System.Web.HttpCookie("LoginCookie", mod.Fname + " " + " " + mod.Lname));
     HttpContext.Response.Cookies.Get("LoginCookie").Expires.AddDays(3);
     return(View(mod));
 }
 public ActionResult Register(RecordEntityModel model)
 {
     if (ModelState.IsValid)
     {
         RecordManager.CreateDBEntry(model.Fname, model.Lname, model.Phone);
         return(RedirectToAction("Users"));
     }
     return(View());
 }
        public ActionResult Update(RecordEntityModel model)
        {
            var saveResult = RecordManager.UpdateRecordInDB(model);

            return(RedirectToRoute(RouteNames.RecordUsers));

            /* ViewBag.ErrorMessage = saveResult.Message;
             * return View(model);*/
        }
Пример #4
0
        public ResultModel <RecordEntityModel> SaveRecord(RecordEntityModel model)
        {
            var result = new ResultModel <RecordEntityModel>
            {
                value = model
            };

            try
            {
                if (string.IsNullOrEmpty(model.Fname))
                {
                    result.Message = "Field First name cannot be left empty!";
                    throw new Exception();
                }
                if (string.IsNullOrEmpty(model.Lname))
                {
                    result.Message = "Field Last name cannot be left empty!";
                    throw new Exception();
                }
                if (string.IsNullOrEmpty(model.Phone))
                {
                    result.Message = "Field Phone cannot be left empty!";
                    throw new Exception();
                }
                if (string.IsNullOrEmpty(model.Password))
                {
                    result.Message = "";
                    throw new Exception("Field Password cannot be left empty!");
                }

                if (!string.IsNullOrEmpty(model.Phone))
                {
                    if (RecordManager.LoadRecords().Any(i => i.Phone == model.Phone))
                    {
                        var findRecordModel = RecordList.Mlist.FirstOrDefault(x => x.Phone == model.Phone);
                        findRecordModel.Fname    = model.Fname;
                        findRecordModel.Lname    = model.Lname;
                        findRecordModel.Phone    = model.Phone;
                        findRecordModel.Password = model.Password;
                    }
                    else
                    {
                        result.Message = "User with specified phone number doesn't exist";
                        throw new Exception();
                    }
                }
                else
                {
                    RecordList.Mlist.Add(model);
                }

                result.isSuccess = true;
            }
            catch (Exception ex) { result.Message = ex.Message; }
            return(result);
        }
Пример #5
0
        static public ResultModel <RecordEntityModel> UpdateRecordInDB(RecordEntityModel model)
        {
            ResultModel <RecordEntityModel> result = new ResultModel <RecordEntityModel>();
            string sql = @"UPDATE dbo.Table1 SET Fname='" + model.Fname + "', Lname = '" + model.Lname + "', Phone = '" + model.Phone + "' WHERE Phone = cast(" + model.Phone + "as BIGINT)";

            SqlDataAccess.SaveData <RecordEntityModel>(sql, null);
            return(new ResultModel <RecordEntityModel>
            {
                isSuccess = true
            });
        }
        public ActionResult Login(RecordEntityModel model)
        {
            var result = RecordManager.GetRecordFromDB(model.Phone);

            if (result.isSuccess)
            {
                return(RedirectToAction("LoggedIn", result.value));
            }
            else
            {
                return(RedirectToAction("Login"));
            }
        }
Пример #7
0
        public static int CreateDBEntry(string fn, string ln, string ph)
        {
            RecordEntityModel data = new RecordEntityModel
            {
                Fname = fn,
                Lname = ln,
                Phone = ph
            };
            string sql = @"insert into dbo.Table1(Fname,Lname,Phone)
                values(@Fname,@Lname,@Phone);";

            return(SqlDataAccess.SaveData(sql, data));
        }
Пример #8
0
        public ResultModel <RecordEntityModel> AddRecord(RecordEntityModel rem)
        {
            ResultModel <RecordEntityModel> result = new ResultModel <RecordEntityModel>
            {
                value = rem
            };

            try
            {
                if (string.IsNullOrEmpty(rem.Fname))
                {
                    result.Message = "Field First name cannot be left empty!";
                    throw new Exception();
                }
                if (string.IsNullOrEmpty(rem.Lname))
                {
                    result.Message = "Field Last name cannot be left empty!";
                    throw new Exception();
                }
                if (string.IsNullOrEmpty(rem.Phone))
                {
                    result.Message = "Field Phone cannot be left empty!";
                    throw new Exception();
                }
                if (string.IsNullOrEmpty(rem.Password))
                {
                    result.Message = "Field Password cannot be left empty!";
                    throw new Exception();
                }
                if (RecordList.Mlist.Any(i => i.Phone == rem.Phone))
                {
                    result.Message = "The user with that Phone number exists already!";
                    throw new Exception();
                }
                RecordList.Mlist.Add(rem);
                result.isSuccess = true;
            }
            catch (Exception) { }

            return(result);
        }