Exemplo n.º 1
0
        public JsonResult UpdateDirection(EXP_DirectionToPaysView model)
        {
            if (ModelState.IsValid)
            {
                DirectionToPayRepository repository = new DirectionToPayRepository();
                EXP_DirectionToPays      m          = repository.GetById(model.Id);

                m.Number        = model.Number;
                m.DirectionDate = model.DirectionDate;
                m.Type          = model.Type;
                m.TotalPrice    = model.PageCount * m.PriceForPage;
                m.PageCount     = model.PageCount;

                repository.Update(m);
                repository.Save();
            }

            return(Json(model, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 2
0
        public JsonResult CreateDirection(EXP_DirectionToPaysView model)
        {
            DirectionToPayRepository repository = new DirectionToPayRepository();

            if (ModelState.IsValid)
            {
                EXP_DirectionToPays m = new EXP_DirectionToPays()
                {
                    Id            = Guid.NewGuid(),
                    Number        = Registrator.GetNumber("DirectionToPay").ToString(),
                    DirectionDate = model.DirectionDate,
                    Type          = model.Type,
                    TypeValue     = string.Empty,
                    //PayerId = ,
                    //PayerValue = ,
                    CreateEmployeeId    = UserHelper.GetCurrentEmployee().Id,
                    CreateEmployeeValue = UserHelper.GetCurrentEmployee().DisplayName,
                    CreateDate          = DateTime.Now
                };
                var status = repository.GetStatusByCode(Dictionary.ExpDirectionToPayStatus.Created);
                m.StatusId    = status.Id;
                m.StatusValue = status.Name;

                repository.Insert(m);
                //repository.Save();
                if (model.Type == 1)
                {
                    if (model.DrugDeclarations != null)
                    {
                        foreach (var modelDrugDeclaration in model.DrugDeclarations)
                        {
                            var drugDeclaration = repository.GetDrugDeclarationById(modelDrugDeclaration.Id);
                            if (drugDeclaration != null)
                            {
                                m.EXP_DrugDeclaration.Add(drugDeclaration);
                                if (drugDeclaration.ContractId != null)
                                {
                                    var payer = repository.GetPayerByContractId(drugDeclaration.ContractId.Value);
                                    if (payer != null)
                                    {
                                        m.PayerId    = payer.Id;
                                        m.PayerValue = payer.Name;
                                    }
                                }
                                m.EXP_DirectionToPays_PriceList = CreateDefaultPriceLists(drugDeclaration);
                            }
                        }
                    }

                    m.TotalPrice = 0;
                    foreach (var expDirectionToPaysPriceList in m.EXP_DirectionToPays_PriceList)
                    {
                        m.TotalPrice += expDirectionToPaysPriceList.Total;
                    }
                }
                else
                {
                    if (model.DrugDeclarations != null)
                    {
                        foreach (var modelDrugDeclaration in model.DrugDeclarations)
                        {
                            var drugDeclaration = repository.GetDrugDeclarationById(modelDrugDeclaration.Id);
                            if (drugDeclaration != null)
                            {
                                m.EXP_DrugDeclaration.Add(drugDeclaration);
                                if (drugDeclaration.ContractId != null)
                                {
                                    var payer = repository.GetPayerByContractId(drugDeclaration.ContractId.Value);
                                    if (payer != null)
                                    {
                                        m.PayerId    = payer.Id;
                                        m.PayerValue = payer.Name;
                                    }
                                }
                            }
                        }
                    }

                    m.TotalPrice   = model.TotalPrice;
                    m.PageCount    = model.PageCount;
                    m.PriceForPage = 2277;
                }

                repository.Save();

                model.Id     = m.Id;
                model.Number = m.Number;
            }

            return(Json(model, JsonRequestBehavior.AllowGet));
        }