Example #1
0
        private TaskTypeDTO Create(TaskTypeViewModel viewModel)
        {
            try
            {
                log.Debug(TaskTypeViewModel.FormatTaskTypeViewModel(viewModel));

                TaskTypeDTO taskType = new TaskTypeDTO();

                // copy values
                viewModel.UpdateDTO(taskType, null); //RequestContext.Principal.Identity.GetUserId());

                // audit
                taskType.CreateBy = null; //RequestContext.Principal.Identity.GetUserId();
                taskType.CreateOn = DateTime.UtcNow;

                // add
                log.Debug("_taskTypeService.AddTaskType - " + TaskTypeDTO.FormatTaskTypeDTO(taskType));

                int id = _taskTypeService.AddTaskType(taskType);

                taskType.TaskTypeId = id;

                log.Debug("result: 'success', id: " + id);

                return(taskType);
            }
            catch (Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
Example #2
0
        /// <summary>
        /// Get TaskType by id
        /// </summary>
        /// <param name="id">TaskType id</param>
        /// <returns>TaskType json view model</returns>
        public IHttpActionResult Get(int id)
        {
            try
            {
                // get
                log.Debug("_taskTypeService.GetTaskType - taskTypeId: " + id + " ");

                var taskType = new TaskTypeViewModel(_taskTypeService.GetTaskType(id));

                log.Debug("_taskTypeService.GetTaskType - " + TaskTypeViewModel.FormatTaskTypeViewModel(taskType));

                log.Debug("result: 'success'");

                //return Json(taskType, JsonRequestBehavior.AllowGet);
                //return Content(JsonConvert.SerializeObject(taskType), "application/json");
                //return taskType;
                //return JsonConvert.SerializeObject(taskType);
                return(Ok(taskType));
            }
            catch (Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
 public async Task <JsonResult> UpdateTaskType([Required] TaskTypeViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return(Json(new InvalidParametersResultModel().AttachModelState(ModelState)));
     }
     return(await JsonAsync(_taskTypeService.UpdateTaskTypeAsync(model)));
 }
 public async Task <JsonResult> AddTaskTypeAsync([Required] TaskTypeViewModel model)
 {
     if (!ModelState.IsValid)
     {
         return(JsonModelStateErrors());
     }
     return(await JsonAsync(_taskTypeService.AddTaskTypeAsync(model)));
 }
Example #5
0
        // GET: TaskType/Create
        public ActionResult Create()
        {
            TaskTypeViewModel taskTypeViewModel = new TaskTypeViewModel()
            {
                RolesSelected     = new string[] { },
                RoleNamesSelected = new string[] { },
                Roles             = GetRoles()
            };

            return(View(taskTypeViewModel));
        }
Example #6
0
        //Adding new Visit
        public async Task <int> AddVisit(TaskTypeViewModel taskTypeViewModel)
        {
            if (_db != null)
            {
                await _db.Visit.AddAsync(taskTypeViewModel.visit);

                await _db.SaveChangesAsync();

                return(1);
            }
            return(0);
        }
Example #7
0
        public async Task <int> AddRequestInfo(TaskTypeViewModel taskTypeViewModel)
        {
            if (_db != null)
            {
                await _db.RequestInformation.AddAsync(taskTypeViewModel.reqInfo);

                await _db.SaveChangesAsync();

                return(1);
            }
            return(0);
        }
Example #8
0
        async void Delete()
        {
            var response = await dialogService.ShowConfirm(
                "Confirm",
                "Are you sure to delete this Task Type ?");

            if (!response)
            {
                return;
            }

            await TaskTypeViewModel.GetInstance().Delete(this);
        }
Example #9
0
        /// <summary>
        /// add task type
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public virtual async Task <ResultModel <Guid> > AddTaskTypeAsync(TaskTypeViewModel model)
        {
            if (model == null)
            {
                return(new InvalidParametersResultModel <Guid>());
            }

            var taskType = _mapper.Map <TaskType>(model);
            await _context.TaskTypes.AddAsync(taskType);

            var result = await _context.PushAsync();

            return(result.Map(taskType.Id));
        }
Example #10
0
 public ActionResult Edit(TaskTypeViewModel taskTypeViewModel)
 {
     if (ModelState.IsValid)
     {
         taskTypeViewModel.TaskTypeDetail.Roles = new List <Capacity>();
         foreach (var r in taskTypeViewModel.RolesSelected)
         {
             Capacity newRole = _repository.GetRoleById(Convert.ToInt16(r));
             taskTypeViewModel.TaskTypeDetail.Roles.Add(newRole);
         }
         _repository.TaskTypeSaveChanges(taskTypeViewModel.TaskTypeDetail);
         return(RedirectToAction("Index"));
     }
     return(View(taskTypeViewModel));
 }
Example #11
0
        //[ValidateAntiForgeryToken]
        /// <summary>
        /// Updates data for an existing TaskType, or creates a new TaskType if the Id is 0
        /// </summary>
        /// <param name="viewModel">TaskType data</param>
        /// <returns>TaskType id</returns>
        public IHttpActionResult Upsert(TaskTypeViewModel viewModel)
        {
            log.Debug("Upsert");

            if (viewModel.TaskTypeId > 0)
            {
                var t = Update(viewModel);
                //return Json(true);
                //return JsonConvert.SerializeObject(t.TaskTypeId);
                return(Ok(t.TaskTypeId));
            }
            else
            {
                var t = Create(viewModel);
                //return Json(t.TaskTypeId);
                //return JsonConvert.SerializeObject(t.TaskTypeId);
                return(Ok(t.TaskTypeId));
            }
        }
Example #12
0
        /// <summary>
        /// update task type
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public virtual async Task <ResultModel> UpdateTaskTypeAsync(TaskTypeViewModel model)
        {
            if (model == null)
            {
                return(new InvalidParametersResultModel());
            }

            var taskType = await _context.TaskTypes.AsNoTracking()
                           .FirstOrDefaultAsync(x => x.Id == model.Id);

            if (taskType == null)
            {
                return(new NotFoundResultModel());
            }

            taskType = _mapper.Map <TaskType>(model);
            _context.TaskTypes.Update(taskType);


            return(await _context.PushAsync());
        }
Example #13
0
        public async Task <int> UpdateRequestInfo(int id, TaskTypeViewModel taskTypeViewModel)
        {
            if (_db != null)
            {
                RequestInformation existItem = _db.RequestInformation.Where(f => f.IdrequestInformation == id).FirstOrDefault();
                if (existItem != null)
                {
                    existItem.SenderId   = taskTypeViewModel.reqInfo.SenderId;
                    existItem.RecieverId = taskTypeViewModel.reqInfo.RecieverId;
                    existItem.Notes      = taskTypeViewModel.reqInfo.Notes;
                    existItem.FileId     = taskTypeViewModel.reqInfo.FileId;
                    existItem.TaskId     = taskTypeViewModel.reqInfo.TaskId;
                }

                _db.RequestInformation.Update(existItem);
                await _db.SaveChangesAsync();

                return(1);
            }
            return(0);
        }
Example #14
0
        //[ValidateAntiForgeryToken]
        /// <summary>
        /// Save a list of TaskType
        /// </summary>
        /// <param name="viewModels">TaskType view models</param>
        /// <param name="id">(not used)</param>
        /// <returns>true if the operation is successfull</returns>
        public IHttpActionResult SaveList(TaskTypeViewModel[] viewModels, int?id)
        {
            try
            {
                log.Debug("SaveList");

                if (viewModels != null)
                {
                    // save list
                    foreach (TaskTypeViewModel viewModel in viewModels)
                    {
                        log.Debug(TaskTypeViewModel.FormatTaskTypeViewModel(viewModel));

                        if (viewModel.TaskTypeId > 0)
                        {
                            var t = Update(viewModel);
                        }
                        else
                        {
                            var t = Create(viewModel);
                        }
                    }
                }
                else
                {
                    log.Error("viewModels: null");
                }

                //return Json(true);
                //return JsonConvert.SerializeObject(true);
                return(Ok(true));
            }
            catch (Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
Example #15
0
        private TaskTypeDTO Update(TaskTypeViewModel viewModel)
        {
            try
            {
                log.Debug(TaskTypeViewModel.FormatTaskTypeViewModel(viewModel));

                // get
                log.Debug("_taskTypeService.GetTaskType - taskTypeId: " + viewModel.TaskTypeId + " ");

                var existingTaskType = _taskTypeService.GetTaskType(viewModel.TaskTypeId);

                log.Debug("_taskTypeService.GetTaskType - " + TaskTypeDTO.FormatTaskTypeDTO(existingTaskType));

                if (existingTaskType != null)
                {
                    // copy values
                    viewModel.UpdateDTO(existingTaskType, null); //RequestContext.Principal.Identity.GetUserId());

                    // update
                    log.Debug("_taskTypeService.UpdateTaskType - " + TaskTypeDTO.FormatTaskTypeDTO(existingTaskType));

                    _taskTypeService.UpdateTaskType(existingTaskType);

                    log.Debug("result: 'success'");
                }
                else
                {
                    log.Error("existingTaskType: null, TaskTypeId: " + viewModel.TaskTypeId);
                }

                return(existingTaskType);
            }
            catch (Exception e)
            {
                // error
                log.Error(e.ToString());

                throw;
            }
        }
Example #16
0
        // GET: TaskType/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            TaskType taskType = _repository.GetTaskTypeById(id);

            if (taskType == null)
            {
                return(HttpNotFound());
            }
            TaskTypeViewModel taskTypeViewModel = new TaskTypeViewModel()
            {
                TaskTypeDetail    = taskType,
                RolesSelected     = GetRolesSelected(taskType),
                RoleNamesSelected = GetRoleNamesSelected(taskType),
                Roles             = GetRoles()
            };

            return(View(taskTypeViewModel));
        }
Example #17
0
        public async Task <int> UpdateVisit(int id, TaskTypeViewModel taskTypeViewModel)
        {
            if (_db != null)
            {
                Visit existItem = _db.Visit.Where(f => f.Idvisit == id).FirstOrDefault();
                if (existItem != null)
                {
                    existItem.UserId    = taskTypeViewModel.visit.UserId;
                    existItem.FactoryId = taskTypeViewModel.visit.FactoryId;
                    existItem.ProjectId = taskTypeViewModel.visit.ProjectId;
                    existItem.TaskId    = taskTypeViewModel.visit.TaskId;
                    existItem.Gifts     = taskTypeViewModel.visit.Gifts;
                    existItem.Notes     = taskTypeViewModel.visit.Notes;
                }

                _db.Visit.Update(existItem);
                await _db.SaveChangesAsync();

                return(1);
            }
            return(0);
        }
Example #18
0
        //Adding new Task
        //each task has a typeID (1=visit, 2=alert, 3=requestInformation)
        //public async Task<int> AddTask(TaskTypeViewModel taskTypeViewModel, PhotoFileViewModel photoFileViewModel)
        public async Task <int> AddTask(TaskTypeViewModel taskTypeViewModel)
        {
            if (_db != null)
            {
                await _db.Task.AddAsync(taskTypeViewModel.task);

                //if the type is 1=visit so add visit
                if (taskTypeViewModel.task.TypeId == 1)
                {
                    await _db.Visit.AddAsync(taskTypeViewModel.visit);

                    await _db.SaveChangesAsync();

                    return(1);
                }
                //if the type is 2=alert so add alert
                else if (taskTypeViewModel.task.TypeId == 2)
                {
                    await _db.Alert.AddAsync(taskTypeViewModel.alert);

                    await _db.SaveChangesAsync();

                    return(1);
                }
                //if the type is 3=RequestInformation so add RequestInformation
                else if (taskTypeViewModel.task.TypeId == 3)
                {
                    await _db.RequestInformation.AddAsync(taskTypeViewModel.reqInfo);

                    await _db.SaveChangesAsync();

                    return(1);
                }
            }
            return(0);
        }
Example #19
0
        public async Task <IActionResult> UpdateTask(TaskTypeViewModel taskTypeViewModel, int id)
        {
            try
            {
                var result = await _task.UpdateTask(id, taskTypeViewModel);

                if (result != 0)
                {
                    var Response = new ResponseViewModel(true, HttpStatusCode.OK, "SUCCESS", result);
                    return(Ok(Response));
                }

                else
                {
                    var Response = new ResponseViewModel(false, HttpStatusCode.NoContent, "failed", null);
                    return(Ok(Response));
                }
            }

            catch
            {
                return(BadRequest());
            }
        }
Example #20
0
        public async Task <IActionResult> AddVisit([FromBody] TaskTypeViewModel taskTypeViewModel)
        {
            try
            {
                var result = await _visit.AddVisit(taskTypeViewModel);

                if (result != 0)
                {
                    var Response = new ResponseViewModel(true, HttpStatusCode.OK, "SUCCESS", result);
                    return(Ok(Response));
                }

                else
                {
                    var Response = new ResponseViewModel(false, HttpStatusCode.NoContent, "failed", null);
                    return(Ok(Response));
                }
            }

            catch
            {
                return(BadRequest());
            }
        }
Example #21
0
 public TaskTypePage()
 {
     InitializeComponent();
     BindingContext = new TaskTypeViewModel();
 }
Example #22
0
        //each update maby affect the data of task type
        public async Task <int> UpdateTask(int id, TaskTypeViewModel taskTypeViewModel)
        {
            if (_db != null)
            {
                Task existItem = _db.Task.Where(f => f.Idtask == id).FirstOrDefault();
                if (existItem != null)
                {
                    existItem.Name = taskTypeViewModel.task.Name;
                    //to update each type data
                    if (existItem.TypeId == taskTypeViewModel.task.TypeId)
                    {
                        if (existItem.TypeId == 1)
                        {
                            var existVisit = _db.Visit.Where(f => f.TaskId == id).FirstOrDefault();
                            existVisit.UserId    = taskTypeViewModel.visit.UserId;
                            existVisit.FactoryId = taskTypeViewModel.visit.FactoryId;
                            existVisit.ProjectId = taskTypeViewModel.visit.ProjectId;
                            //existVisit.Gifts = taskTypeViewModel.visit.Gifts;
                            //existVisit.Notes = taskTypeViewModel.visit.Notes;

                            _db.Visit.Update(existVisit);
                        }
                        else if (existItem.TypeId == 2)
                        {
                            var existAlert = _db.Alert.Where(f => f.TaskId == id).FirstOrDefault();
                            existAlert.SenderId   = taskTypeViewModel.alert.SenderId;
                            existAlert.RecieverId = taskTypeViewModel.alert.RecieverId;
                            existAlert.Notes      = taskTypeViewModel.alert.Notes;
                            existAlert.FileId     = taskTypeViewModel.alert.FileId;
                            _db.Alert.Update(existAlert);
                        }
                        else if (existItem.TypeId == 3)
                        {
                            var existRequest = _db.RequestInformation.Where(f => f.TaskId == id).FirstOrDefault();
                            existRequest.SenderId   = taskTypeViewModel.reqInfo.SenderId;
                            existRequest.RecieverId = taskTypeViewModel.reqInfo.RecieverId;
                            existRequest.Notes      = taskTypeViewModel.reqInfo.Notes;
                            existRequest.FileId     = taskTypeViewModel.reqInfo.FileId;
                            _db.RequestInformation.Update(existRequest);
                        }
                    }
                    //user not allowed to change task type
                    else
                    {
                        return(0);
                    }
                    existItem.StatusId      = taskTypeViewModel.task.StatusId;
                    existItem.ResponsibleId = taskTypeViewModel.task.ResponsibleId;
                    existItem.CreatorId     = taskTypeViewModel.task.CreatorId;
                    existItem.Content       = taskTypeViewModel.task.Content;
                    existItem.StartDate     = taskTypeViewModel.task.StartDate;
                    existItem.EndDate       = taskTypeViewModel.task.EndDate;
                    existItem.FileId        = taskTypeViewModel.task.FileId;
                    existItem.PhotoId       = taskTypeViewModel.task.PhotoId;
                }

                _db.Task.Update(existItem);
                await _db.SaveChangesAsync();

                return(1);
            }
            return(0);
        }