Beispiel #1
0
        public BaseResult Save(ToDoTaskEditView model)
        {
            using (var repo = new ToDoRepository <ToDoList>())
            {
                var result = new LoginResult();

                var toDoList = repo.SingleOrDefault(o => o.UserId == model.UserId && o.Id == model.ListId);

                if (toDoList == null)
                {
                    result.ResultType    = ResultType.BusinessError;
                    result.ResultMessage = $"ToDoList not found by id:{model.ListId}";
                    return(result);
                }

                var task = new ToDoTask()
                {
                    ToDoListId            = toDoList.Id,
                    Desc                  = model.Desc,
                    NotificationType      = model.NotificationType,
                    NotificationRequested = model.NotificationRequested,
                    NotificationDate      = model.NotificationDate
                };

                model.Id = task.Id;
                toDoList.Tasks.Add(task);

                repo.SaveChanges();

                return(result);
            }
        }
Beispiel #2
0
        public JsonResult Update(ToDoTaskEditView model)
        {
            if (!ModelState.IsValid)
            {
                return(AJAXResult(false, GetModelStateError()));
            }
            if (model.NotificationRequested)
            {
                if (model.NotificationDate == null || model.NotificationDate == default(DateTime))
                {
                    return(AJAXResult(false, "Please specify norification date."));
                }
                if (model.NotificationTime == null || model.NotificationTime == default(DateTime))
                {
                    return(AJAXResult(false, "Please specify norification time."));
                }
                var date = model.NotificationDate.Value;
                var time = model.NotificationTime.Value;
                model.NotificationDate = new DateTime(date.Year, date.Month, date.Day, time.Hour, time.Minute, 0);
                model.NotificationTime = model.NotificationDate;
                if (model.NotificationDate.Value < DateTime.Now)
                {
                    return(AJAXResult(false, "Norification date must be in future."));
                }
            }
            model.UserId = UserId;
            var result = service.Update(model);

            return(AJAXResult(_result: result.ResultType == ResultType.Success, _message: result.ResultMessage, _data: model));
        }
Beispiel #3
0
        public BaseResult Update(ToDoTaskEditView model)
        {
            using (var repo = new ToDoRepository <ToDoTask>())
            {
                var result = new LoginResult();

                var dbModel = repo.SingleOrDefault(o => o.List.UserId == model.UserId && o.Id == model.Id);

                if (dbModel == null)
                {
                    result.ResultType    = ResultType.BusinessError;
                    result.ResultMessage = $"Item not found by id:{model.Id}";
                    return(result);
                }

                dbModel.Desc                  = model.Desc;
                dbModel.NotificationType      = model.NotificationType;
                dbModel.NotificationRequested = model.NotificationRequested;
                dbModel.NotificationDate      = model.NotificationDate;
                repo.SaveChanges();

                return(result);
            }
        }