Example #1
0
        public async Task <ActionResult <ToDoTaskModel> > Put(int id, ToDoTaskModel model)
        {
            try
            {
                // Find our existing entity to update
                var oldTask = await repository.GetTaskByIdAsync(id);

                if (oldTask == null)
                {
                    return(NotFound($"Could not find task with id of {id}"));
                }

                // Update existing entity with past in model data through the update model
                mapper.Map(model, oldTask);

                // On success return the update entity via the model
                if (await repository.SaveChangesAsync())
                {
                    return(mapper.Map <ToDoTaskModel>(oldTask));
                }
                return(BadRequest());
            }
            catch (Exception ex)
            {
                logger.LogError($"Failed to update Task: {ex}");
                return(BadRequest("Failed to update Task"));
            }
        }
Example #2
0
        public async Task <ActionResult <ToDoTaskModel> > Post(ToDoTaskModel model)
        {
            try
            {
                // Map the incoming data to the entity
                var task = mapper.Map <ToDoTask>(model);
                // Call the repository to add the entity
                repository.Add(task);
                // On successful save...
                if (await repository.SaveChangesAsync())
                {
                    // Generate the URI for the created resource
                    var returnLink = linkGenerator.GetPathByAction("Get",
                                                                   "ToDoTasks",
                                                                   new { id = task.Id });
                    // If link generation failed return bad request
                    if (string.IsNullOrWhiteSpace(returnLink))
                    {
                        return(BadRequest("Could not use current id"));
                    }
                    // return created object and it's location
                    return(Created(returnLink, mapper.Map <ToDoTaskModel>(task)));
                }
            }
            catch (Exception ex)
            {
                logger.LogError($"Failed to create Task: {ex}");
                return(BadRequest("Failed to create Task"));
            }

            return(BadRequest());
        }
Example #3
0
        public async Task <IActionResult> Update([FromBody] ToDoTaskModel todoTask)
        {
            if (todoTask == null)
            {
                return(NotFound());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            Guid todoID;

            if (!Guid.TryParse(todoTask.ID, out todoID))
            {
                return(NotFound());
            }

            var userName = HttpContext.User.Identity.Name;

            var uID = Ctx.Users.First(u => u.Name == userName).UserID;

            var dbTask = await(from t in Ctx.ToDos
                               where t.ToDoID == todoID && t.UserID == uID
                               select t).FirstOrDefaultAsync();

            if (dbTask == null)
            {
                return(NotFound());
            }

            dbTask.Title       = todoTask.Title;
            dbTask.Description = todoTask.Description;
            dbTask.Product     = todoTask.Product;
            dbTask.Type        = todoTask.Type;
            if (!dbTask.DoneDate.HasValue && todoTask.Done)
            {
                dbTask.DoneDate = DateTime.UtcNow;
            }
            dbTask.Priority = todoTask.Priority;


            try
            {
                await Ctx.SaveChangesAsync();

                return(Ok(new ToDoTask(dbTask)));
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!Ctx.ToDos.Any(a => a.ToDoID == todoID))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }
        }
Example #4
0
        public async Task <IActionResult> Create([FromBody] ToDoTaskModel todoTask)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var userName = HttpContext.User.Identity.Name;

            var uID   = Ctx.Users.First(u => u.Name == userName).UserID;
            var dbEnt = new ToDo()
            {
                UserID      = uID,
                Title       = todoTask.Title,
                Description = todoTask.Description,
                Product     = todoTask.Product,
                Type        = todoTask.Type,
                Priority    = todoTask.Priority
            };

            Ctx.ToDos.Add(dbEnt);

            await Ctx.SaveChangesAsync();

            return(CreatedAtAction(nameof(Get), new { id = dbEnt.ToDoID }, todoTask));
        }
        public void AddTask(ToDoTaskModel request)
        {
            var user = _userRepository.GetAll()
                       .FirstOrDefault(x => x.Id == request.UserId);

            if (user == null)
            {
                throw new ToDoTaskException("User does not exists.");
            }
            if (string.IsNullOrWhiteSpace(request.TaskName))
            {
                throw new ToDoTaskException("TaskName is required.");
            }
            if (string.IsNullOrWhiteSpace(request.TaskDescription))
            {
                throw new ToDoTaskException("Description is required.");
            }
            if (request.TaskSchedule == null)
            {
                throw new ToDoTaskException("Time Schedule is required");
            }

            var toDoTask = new ToDoTask
            {
                TaskName        = request.TaskName,
                TaskDescription = request.TaskDescription,
                TaskSchedule    = request.TaskSchedule
            };

            _todoRepository.Create(toDoTask);
        }
        public static List <ToDoTaskModel> ToToDoTask(DbDataReader readers)
        {
            if (readers == null)
            {
                return(null);
            }
            var models = new List <ToDoTaskModel>();

            while (readers.Read())
            {
                var model = new ToDoTaskModel
                {
                    Id          = Convert.ToString(readers["Id"]),
                    Title       = Convert.IsDBNull(readers["Title"]) ? string.Empty : Convert.ToString(readers["Title"]),
                    Description = Convert.IsDBNull(readers["Description"]) ? string.Empty : Convert.ToString(readers["Description"]),
                    Completed   = Convert.IsDBNull(readers["Completed"]) ? false : Convert.ToBoolean(readers["Completed"]),
                    CreatedAt   = Convert.IsDBNull(readers["CreatedAt"]) ? (DateTime?)null : Convert.ToDateTime(readers["CreatedAt"]),
                    CreatedById = Convert.IsDBNull(readers["CreatedById"]) ? string.Empty : Convert.ToString(readers["CreatedById"]),
                };

                models.Add(model);
            }

            return(models);
        }
 /// <summary>
 /// This function is binding data from model to GUI
 /// </summary>
 /// <param name="toDoTaskModel"></param>
 /// <param name="labelTitle"></param>
 /// <param name="labelStatus"></param>
 /// <param name="labelPriority"></param>
 /// <param name="richTextBoxDescription"></param>
 public static void SetUpMyDetails(ToDoTaskModel toDoTaskModel, ref Label labelTitle, ref Label labelStatus, ref Label labelPriority, ref RichTextBox richTextBoxDescription)
 {
     labelTitle.Text = toDoTaskModel.Name;
     SetColorText.SetStatusText(ref labelStatus, toDoTaskModel.Status);
     SetColorText.SetPriorityText(ref labelPriority, toDoTaskModel.Priority);
     richTextBoxDescription.Text = toDoTaskModel.Description;
 }
 public static ToDoTask ToEntity(this ToDoTaskModel model)
 {
     return(new ToDoTask()
     {
         Id = model.Id,
         Text = model.Text,
         Checked = model.Checked,
         ToRemind = model.ToRemind,
         ToDoList = model.ToDoList
     });
 }
 public ActionResult Post([FromBody] ToDoTaskModel request)
 {
     try
     {
         _toDoService.AddTask(request);
         return(Ok("Success"));
     }
     catch (ToDoTaskException ex)
     {
         Debug.WriteLine($"TODO:{ex.Message}");
         return(BadRequest(ex.Message));
     }
     catch (Exception ex)
     {
         Debug.WriteLine($"TODO:{ex.Message}");
         return(BadRequest(ex.Message));
     }
 }
        public ResponseModel SaveToDoTask(ToDoTaskModel model)
        {
            var errMessage     = string.Empty;
            var queryParamList = new QueryParamList
            {
                new QueryParamObj {
                    ParamDirection = ParameterDirection.Input, ParamName = "@Id", ParamValue = string.IsNullOrEmpty(model.Id)?Guid.NewGuid().ToString():model.Id
                },
                new QueryParamObj {
                    ParamDirection = ParameterDirection.Input, ParamName = "@Title", ParamValue = model.Title
                },
                new QueryParamObj {
                    ParamDirection = ParameterDirection.Input, ParamName = "@Description", ParamValue = model.Description
                },
                new QueryParamObj {
                    ParamDirection = ParameterDirection.Input, ParamName = "@CreatedAt", ParamValue = DateTime.UtcNow, DBType = DbType.DateTime
                },
                new QueryParamObj {
                    ParamDirection = ParameterDirection.Input, ParamName = "@CreatedById", ParamValue = model.CreatedById
                }
            };

            const string sql = @"IF NOT EXISTS(SELECT TOP 1 P.Id FROM ResourceTracker_ToDoTask P WHERE P.Id=@Id)
                                BEGIN
                                DECLARE @companyId int
                                 SELECT TOP 1  @companyId=CompanyId FROM ResourceTracker_EmployeeUser WHERE UserId=@CreatedById 
                                 INSERT INTO ResourceTracker_ToDoTask(Id,Title,Description,CreatedAt,CreatedById,CompanyId,Completed)
				                 VALUES(@Id,@Title,@Description,@CreatedAt,@CreatedById,@CompanyId,0)
                                END
                                ELSE
                                BEGIN
                                  UPDATE ResourceTracker_ToDoTask SET Title=@Title,Description=@Description
	                              WHERE Id=@Id
                                END";

            DBExecCommandEx(sql, queryParamList, ref errMessage);

            return(new ResponseModel {
                Success = string.IsNullOrEmpty(errMessage)
            });
        }
Example #11
0
        public ToDoTaskControl(ToDoTaskModel toDoTaskModel, IToDoListService toDoListService, IToDoTaskDao toDoTaskDao)
        {
            InitializeComponent();

            _toDoListService = toDoListService;
            _toDoTaskModel   = toDoTaskModel;
            _toDoTaskDao     = toDoTaskDao;

            labelRemindBell.Image = _toDoTaskModel.ToEntity().HasValidReminder()
                ? Properties.Resources.Bell.ResizeTo(Constants.Sizes.DefaultBellSize) : null;
            labelTaskText.Text      = _toDoTaskModel.Text;
            checkBoxChecked.Checked = _toDoTaskModel.Checked;

            var contextMenu = new ContextMenu();

            contextMenu.MenuItems.Add(new MenuItem(Constants.Interface.TaskContextMenu.ToRemind,
                                                   new EventHandler(CheckUncheckReminder_Opening)));
            contextMenu.MenuItems.Add(new MenuItem(Constants.Interface.TaskContextMenu.Edit,
                                                   new EventHandler(EditItem_Opening)));
            contextMenu.MenuItems.Add(new MenuItem(Constants.Interface.TaskContextMenu.Delete,
                                                   new EventHandler(DeleteItem_Opening)));

            tableLayoutPanel1.ContextMenu = contextMenu;
        }
 public TaskToDo Map(ToDoTaskModel toDoTaskModel)
 {
     return(_Mapper.Map <TaskToDo>(toDoTaskModel));
 }
 /// <summary>
 /// This function is input data from model to textBoxes
 /// </summary>
 /// <param name="toDoTaskModel"></param>
 /// <param name="name"></param>
 /// <param name="fkDay"></param>
 /// <param name="description"></param>
 public static void SetUpTextValuesInForm(ToDoTaskModel toDoTaskModel, ref TextBox name, ref int fkDay, ref RichTextBox description)
 {
     description.Text = toDoTaskModel.Description;
     name.Text        = toDoTaskModel.Name;
     fkDay            = toDoTaskModel.DayId;
 }
Example #14
0
 public FormAdd(bool isEdition, ToDoTaskModel taskModel) : this(isEdition)
 {
     this.taskModel = taskModel;
     SetUpValuesInForm();
 }
Example #15
0
        public IHttpActionResult SaveToDoTask(ToDoTaskModel model)
        {
            var result = _taskRepository.SaveToDoTask(model);

            return(Ok(result));
        }