Пример #1
0
        public ActionResult Delete(int id)
        {
            var  action_srv = CompositionRoot.Resolve <IActionService>();
            bool has_error  = false;
            ServiceActionViewModel model = null;

            try {
                var action = action_srv.GetActionById(id);
                if (action == null)
                {
                    ModelState.AddModelError("", "Работа не найдена");
                    has_error = true;
                }

                model = ServiceActionModelConverter.ToModel(action);
            }
            catch (DomainException e) {
                ModelState.AddModelError("", e);
                has_error = true;
            }

            if (has_error)
            {
                return(RedirectToAction("Index", new { date = model.Date.ToString("dd.MM.yyyy"), user_id = model.ExpertId }));
            }

            return(View(model));
        }
Пример #2
0
        public ActionResult EditPartial(Int64 id)
        {
            bool has_error = false;
            ServiceActionViewModel model = null;

            try {
                var action = ActionService.GetActionById(id);
                if (action == null)
                {
                    ModelState.AddModelError("", "Работа не найдена");
                    has_error = true;
                }

                model = ServiceActionModelConverter.ToModel(action);
                model.IsItInDialog = true;
            }
            catch (DomainException e) {
                ModelState.AddModelError("", e);
                has_error = true;
            }

            if (has_error)
            {
                return(RedirectToAction("Index", new { date = model.Date.ToString("dd.MM.yyyy"), user_id = model.ExpertId }));
            }

            PrepareForCreate();

            return(PartialView("_Edit", model));
        }
Пример #3
0
        public ActionResult Create(ServiceActionViewModel model)
        {
            if (ModelState.IsValid)
            {
                var  action_srv = CompositionRoot.Resolve <IActionService>();
                bool has_error  = false;

                Int64 id = -1;

                try {
                    id = action_srv.Add(model.Date, model.ServiceId, model.Customer, model.TypeId, model.CustomerTypeId, model.ExpertId, model.ServiceChildId, model.IsNonresident, model.FreeVisit, model.Comments);
                }
                catch (Exception e) {
                    has_error = true;
                    ModelState.AddModelError("", string.Format("{0} \r\n {1}", e.Message, e.StackTrace));
                }

                if (!has_error)
                {
                    return(RedirectToAction("Index", new { date = model.Date.ToString("dd.MM.yyyy"), user_id = model.ExpertId }));
                }
            }

            PrepareForCreate();

            return(View("Edit", model));
        }
Пример #4
0
        public ActionResult Edit(ServiceActionViewModel model)
        {
            bool   has_error    = false;
            string errorMessage = string.Empty;

            if (ModelState.IsValid)
            {
                try {
                    var action = ActionService.GetActionById(model.Id);

                    if (action == null)
                    {
                        throw new DomainException($"Прием с идентификатором {model.Id} не найден в базе данных");
                    }

                    ServiceActionModelConverter.FromModel(model, action);

                    if (action.ServiceChild != null && !Equals(action.Service.Id, action.ServiceChild.Parent.Id))
                    {
                        throw new DomainException("Подуслуга не связана с услугой");
                    }

                    ActionService.Update(action);
                }
                catch (DomainException e) {
                    ModelState.AddModelError("", e.Message);
                    errorMessage = e.Message;
                    has_error    = true;
                }
                catch (Exception e) {
                    if (!model.IsItInDialog)
                    {
                        throw e;
                    }
                    Logger.Error(e);
                    errorMessage = $"Ошибка при сохранении данныхъ {e.Message}";
                    has_error    = true;
                }

                if (!has_error && !model.IsItInDialog)
                {
                    return(RedirectToAction("Index", new { date = model.Date.ToString("dd.MM.yyyy"), user_id = model.ExpertId }));
                }
            }


            PrepareForCreate();

            if (model.IsItInDialog)
            {
                if (!has_error)
                {
                    return(Json(true));
                }
                return(Json(new { message = errorMessage }));
            }

            return(View(model));
        }
 public static void FromModel(ServiceActionViewModel model, ServiceAction action)
 {
     /*action.Id = model.Id;*/
     action.User          = UserService.GetUserById(model.ExpertId);
     action.Customer      = model.Customer;
     action.Service       = ServiceService.GetServiceById(model.ServiceId);
     action.Date          = model.Date;
     action.Type          = ActionTypeService.GetTypeById(model.TypeId);
     action.Comments      = model.Comments;
     action.ServiceChild  = ServiceService.GetServiceById(model.ServiceChildId);
     action.IsNonresident = model.IsNonresident;
     action.FreeVisit     = model.FreeVisit;
     action.CustomerType  = model.CustomerTypeId == CustomerType.Empty.Id
         ? null
         : CustomerService.GetTypeById(model.CustomerTypeId);
 }
Пример #6
0
        public ActionResult Create(string date, Int64 user_id)
        {
            var model = new ServiceActionViewModel();

            model.ExpertId = user_id;
            DateTime createDate = DateTime.Today;

            if (!string.IsNullOrEmpty(date))
            {
                DateTime.TryParse(date, CultureInfo.GetCultureInfo("ru-RU"), DateTimeStyles.AssumeLocal, out createDate);
            }

            model.Date = createDate;
            PrepareForCreate();

            return(View("Edit", model));
        }
Пример #7
0
        public ActionResult Delete(ServiceActionViewModel model)
        {
            bool has_error = false;

            try {
                ActionService.Delete(model.Id);
            }
            catch (DomainException e) {
                ModelState.AddModelError("", e);
                has_error = true;
            }

            if (!has_error)
            {
                return(RedirectToAction("Index", new { date = model.Date.ToString("dd.MM.yyyy"), user_id = model.ExpertId }));
            }
            else
            {
                return(View());
            }
        }
        public static ServiceActionViewModel ToModel(ServiceAction entity)
        {
            var item = new ServiceActionViewModel
            {
                Id            = entity.Id,
                ExpertId      = entity.User.Id,
                Expert        = entity.User.Name,
                TypeId        = entity.Type.Id,
                Type          = entity.Type.Caption,
                Date          = entity.Date,
                Customer      = entity.Customer,
                Comments      = entity.Comments,
                IsNonresident = entity.IsNonresident,
                FreeVisit     = entity.FreeVisit
            };

            if (entity.Service != null)
            {
                item.ServiceId      = entity.Service.Id;
                item.Service        = entity.Service.Caption;
                item.OrganizationId = entity.Service.Organization.Id;
                item.Organization   = entity.Service.Organization.Caption;
            }

            if (entity.ServiceChild != null)
            {
                item.ServiceChildId = entity.ServiceChild.Id;
                item.ServiceChild   = entity.ServiceChild.Caption;
            }

            if (entity.CustomerType != null)
            {
                item.CustomerTypeId = entity.CustomerType.Id;
                item.CustomerType   = entity.CustomerType.Caption;
            }

            return(item);
        }