コード例 #1
0
        public async Task <int> SaveAsync(DistributorViewModel record)
        {
            Distributor distributor = null;

            if (record.Id != null)
            {
                distributor = _unitOfWork.Distributors.Get(record.Id.Value);
                if (distributor == null)
                {
                    throw new Exception("Invalid Distributor Id");
                }

                distributor.UpdatedBy   = System.Web.HttpContext.Current.User.Identity.Name;
                distributor.UpdatedDate = DateTime.Now;
            }
            else
            {
                distributor = new Distributor();
                _unitOfWork.Distributors.Add(distributor);

                distributor.CreatedBy = System.Web.HttpContext.Current.User.Identity.Name;
            }

            distributor.Code    = record.Code;
            distributor.Name    = record.Name;
            distributor.Address = record.Address;

            return(await _unitOfWork.CompleteAsync());
        }
コード例 #2
0
 public ActionResult Edit(DistributorViewModel model)
 {
     if (ModelState.IsValid)
     {
         if (model.Parent == Guid.Empty)
         {
             // Add new
             var         parentUser  = Session["UserData"] as User;
             Distributor distributor = Mapper.Map <DistributorViewModel, Distributor>(model);
             distributor.Parent = parentUser.UserId;
             _distributorService.CreateDistributor(distributor);
         }
         else
         {
             model.Password = "******";
             try
             {
                 Distributor distributor = _distributorService.GetUser(model.UserId);
                 Mapper.Map <DistributorViewModel, Distributor>(model, distributor);
                 _distributorService.UpdateUser(distributor);
             }
             catch (Exception ex)
             {
                 ModelState.AddModelError("Error", ex.Message);
             }
         }
         _distributorService.SaveDistributor();
     }
     else
     {
     }
     return(Json(new { Result = "Success" }));
 }
コード例 #3
0
        public ActionResult Index()
        {
            var model = new DistributorViewModel();

            model.AreaList = Ioc.Get <IAreaService>().GetList();
            return(View(model));
        }
コード例 #4
0
 public ActionResult Edit(DistributorViewModel model)
 {
     if (ModelState.IsValid)
     {
         if (model.Parent == Guid.Empty)
         {
             // Add new
             var parentUser = Session["UserData"] as User;
             Distributor distributor = Mapper.Map<DistributorViewModel, Distributor>(model);
             distributor.Parent = parentUser.UserId;
             _distributorService.CreateDistributor(distributor);
         }
         else
         {
             model.Password = "******";
             try
             {
                 Distributor distributor = _distributorService.GetUser(model.UserId);
                 Mapper.Map<DistributorViewModel, Distributor>(model, distributor);
                 _distributorService.UpdateUser(distributor);
             }
             catch (Exception ex)
             {
                 ModelState.AddModelError("Error", ex.Message);
             }
         }
         _distributorService.SaveDistributor();
     }
     else {
     }
     return Json(new { Result = "Success" });
 }
        public ActionResult CreateContract()
        {
            isAdminLogged();
            ContractDistributorVM model = new ContractDistributorVM();

            // Get List of old distributors
            IList <DistributorList>      oldDisList  = dis_Service.GetList(null, false);
            IList <DistributorViewModel> _oldDisList = new List <DistributorViewModel>();
            DistributorViewModel         _oldDis;

            if (oldDisList.Count != 0)
            {
                foreach (DistributorList dis in oldDisList)
                {
                    _oldDis               = new DistributorViewModel();
                    _oldDis.address       = dis.Dis.address;
                    _oldDis.Email         = dis.Dis.Email;
                    _oldDis.idDistributor = dis.Dis.idDistributor;
                    _oldDis.name          = dis.Dis.name;
                    _oldDis.phone         = dis.Dis.phone;
                    _oldDisList.Add(_oldDis);
                }
                model.oldDis = _oldDisList;
            }

            // Get List of approved potential distributor
            IList <PotentialDistributor> pDisList    = pDis_Service.SearchByStatus(3);
            IList <PdisRepViewModel>     pDisRepList = new List <PdisRepViewModel>();
            PdisRepViewModel             pDisRep;

            if (pDisList.Count != 0)
            {
                foreach (PotentialDistributor item in pDisList)
                {
                    pDisRep = new PdisRepViewModel();
                    pDisRep.pDis.address       = item.address;
                    pDisRep.pDis.Email         = item.Email;
                    pDisRep.pDis.idDistributor = item.idDistributor;
                    pDisRep.pDis.name          = item.name;
                    pDisRep.pDis.phone         = item.phone;

                    foreach (Representative rep in item.Representatives)
                    {
                        if (rep.PotentialDistributor.idDistributor == item.idDistributor)
                        {
                            pDisRep.rep.email            = rep.email;
                            pDisRep.rep.idRepresentative = rep.idRepresentative;
                            pDisRep.rep.name             = rep.name;
                            pDisRep.rep.phone            = rep.phone;
                            pDisRep.rep.title            = rep.title;
                        }
                    }
                    pDisRepList.Add(pDisRep);
                }
                model.pDis = pDisRepList;
            }

            return(View(model));
        }
コード例 #6
0
 public ActionResult Detail(DistributorViewModel model)
 {
     if (model == null)
     {
         model = new DistributorViewModel();
     }
     return(View(model));
 }
コード例 #7
0
        public override void OnCollectorCreated()
        {
            base.OnCollectorCreated();

            Maps        = new MapViewModel(EventAnalyzer, new FileSystem());
            DashBoard   = new DashBoardViewModel(EventAnalyzer);
            Distributor = new DistributorViewModel(EventAnalyzer, ConfigMgr.DistributorPort);
        }
コード例 #8
0
        public IActionResult Index()
        {
            var model = new DistributorViewModel()
            {
                Distributors = DistributorDB.GetInstance().GetAllDistributors(userObj),
                //Companies = CompanyDB.GetInstance().GetCompanyList(userObj),
                CompanyPartners = CompanyPartnerDB.GetInstance().GetAllCompanyPartners()
            };

            return(View(model));
        }
コード例 #9
0
        public async Task <IActionResult> Details(DistributorViewModel distributorViewModel)
        {
            DistributorServiceModel     distributorFromDB = this.distributorService.GetById(distributorViewModel.Id);
            List <ContractServiceModel> contractsForDistributorServiceModel = await this.contractService.FindContractsByDistributorId(distributorViewModel.Id).ToListAsync();

            List <ContractViewModel> contractsForDistributorViewModel = AutoMapper.Mapper.Map <List <ContractViewModel> >(contractsForDistributorServiceModel);
            DistributorViewModel     distributor = distributorFromDB.To <DistributorViewModel>();

            distributor.ContractsFound = contractsForDistributorViewModel;
            distributor.SelectedTab    = distributorViewModel.SelectedTab;
            return(this.View(distributor));
        }
コード例 #10
0
        // GET: Distribution/Create
        public ActionResult Create()
        {
            var company         = new Distributor();
            var companyAdmninId = company.Distirbutor_Id;
            var user_           = User.Identity;
            var vm = new DistributorViewModel()
            {
                User        = user_.Name,
                Distributor = company,
            };

            return(View(vm));
        }
コード例 #11
0
        public void SaveDistributor(DistributorViewModel model)
        {
            var distrib = new Distributor();

            if (model.DistributorId > 0)
            {
                distrib = db.Distributors.FirstOrDefault(m => m.DistributorId == model.DistributorId);
            }

            using (var dbContextTransaction = db.Database.BeginTransaction())
            {
                distrib.Name     = model.Name;
                distrib.IsActive = true;
                distrib.Phone    = string.IsNullOrEmpty(model.Phone) ? "" : CommonBusinessLogic.GetDigits(model.Phone);
                distrib.Address  = model.Address;
                distrib.City     = model.City;
                distrib.Company  = model.Company;

                if (model.DistributorId == 0)
                {
                    distrib.CreatedBy = (int)GetLoggedInUserId();
                    distrib.CreatedOn = DateTime.UtcNow;

                    db.Distributors.Add(distrib);
                }
                else
                {
                    distrib.UpdatedBy = (int)GetLoggedInUserId();
                    distrib.UpdatedOn = DateTime.UtcNow;

                    db.Entry(distrib).State = System.Data.Entity.EntityState.Modified;
                }
                db.SaveChanges();

                db.DistributorManufacturers.RemoveRange(db.DistributorManufacturers.Where(x => x.DistributorId == distrib.DistributorId));

                foreach (var manu in model.ManufacturerIds)
                {
                    var distribmanufact = new DistributorManufacturer();

                    distribmanufact.DistributorId  = distrib.DistributorId;
                    distribmanufact.ManufacturerId = manu;

                    db.DistributorManufacturers.Add(distribmanufact);
                    db.SaveChanges();
                }

                dbContextTransaction.Commit();
            }
        }
コード例 #12
0
        public DistributorViewModel GetDistributorViewModel(int distributorId, DistributorViewModel viewModel = null)
        {
            viewModel = viewModel ?? new DistributorViewModel();

            var distrib = db.Distributors.FirstOrDefault(c => c.DistributorId == distributorId);

            if (distrib != null)
            {
                Transform.FromObjectToObject(distrib, viewModel);

                viewModel.ManufacturerIds = db.DistributorManufacturers.Where(c => c.DistributorId == distrib.DistributorId).Select(c => c.ManufacturerId).ToList();
            }

            return(viewModel);
        }
コード例 #13
0
        // GET : /Distributor/Edit
        public ActionResult Edit(string distributorId)
        {
            DistributorViewModel distributorVM = new DistributorViewModel();
            if (string.IsNullOrWhiteSpace(distributorId))
            {
                return PartialView("_Edit", distributorVM);
            }
            else
            {
                var distributorGuid = Guid.Parse(distributorId);
                Distributor distributor = _distributorService.GetUser(distributorGuid);
                distributorVM = Mapper.Map<Distributor, DistributorViewModel>(distributor);

                return PartialView("_Edit", distributorVM);
            }
        }
コード例 #14
0
        // GET : /Distributor/Edit
        public ActionResult Edit(string distributorId)
        {
            DistributorViewModel distributorVM = new DistributorViewModel();

            if (string.IsNullOrWhiteSpace(distributorId))
            {
                return(PartialView("_Edit", distributorVM));
            }
            else
            {
                var         distributorGuid = Guid.Parse(distributorId);
                Distributor distributor     = _distributorService.GetUser(distributorGuid);
                distributorVM = Mapper.Map <Distributor, DistributorViewModel>(distributor);

                return(PartialView("_Edit", distributorVM));
            }
        }
コード例 #15
0
        public ActionResult Create(DistributorViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            Distributor entity = model.ToEntity();

            entity.ParentId = 0;
            entity.AreaId   = "11010000";
            entity.Street   = "上海";
            entity.Lat      = 29;
            entity.Lng      = 30;
            entity.State    = 1;
            entity.Path     = "aaa";
            _distributorService.Add(entity);
            return(RedirectToAction("Detail", entity.ToModel()));
        }
コード例 #16
0
        public ActionResult Edit(DistributorViewModel model)
        {
            DistributorBusinessLogic bl           = new DistributorBusinessLogic();
            MessageModel             messageModel = new MessageModel();

            try
            {
                if (ModelState.IsValid)
                {
                    bl.SaveDistributor(model);
                    messageModel.Message = "Distributor has been saved successfully";
                }
                else
                {
                    throw new InvalidModelException();
                }
            }
            catch (InvalidModelException ex)
            {
                messageModel.Message = "Invalid information";
                messageModel.Type    = Enumeration.MessageType.Error;
                logger.Error(messageModel.Message, ex);
            }
            catch (System.Exception ex)
            {
                messageModel.Message = "An error has occured while saving Distributor";
                messageModel.Type    = Enumeration.MessageType.Error;
                logger.Error(messageModel.Message, ex);
            }
            finally
            {
                TempData["MESSAGE"] = JsonConvert.SerializeObject(new { Message = messageModel.Message, Type = messageModel.Type });
            }

            if (messageModel.Type != Enumeration.MessageType.Success)
            {
                return(View(model));
            }
            else
            {
                return(Redirect(CommonFunction.GetBaseUrlForActions("Index", "Distributor")));
            }
        }
コード例 #17
0
        public ActionResult Add(DistributorViewModel model)
        {
            DistributorBusinessLogic bl           = new DistributorBusinessLogic();
            MessageModel             messageModel = new MessageModel();

            try
            {
                if (ModelState.IsValid)
                {
                    bl.SaveDistributor(model);
                    messageModel.Message = "Distributor has been saved successfully";
                }
                else
                {
                    throw new InvalidModelException();
                }
            }
            catch (InvalidModelException ex)
            {
                messageModel.Message = "Invalid information";
                messageModel.Type    = Enumeration.MessageType.Error;
                logger.Error(messageModel.Message, ex);
            }
            catch (System.Exception ex)
            {
                messageModel.Message = "An error has occured while saving Distributor";
                messageModel.Type    = Enumeration.MessageType.Error;
                logger.Error(messageModel.Message, ex);
            }

            if (messageModel.Type != Enumeration.MessageType.Success)
            {
                return(View(model));
            }
            else
            {
                return(Redirect(CommonFunction.GetBaseUrlForActions("Index", "Distributor")));
            }

            //return Json(new { model, messageModel }, JsonRequestBehavior.AllowGet);
        }
コード例 #18
0
        public async Task <JsonResult> SaveAsync(DistributorViewModel record)
        {
            try
            {
                DistributorModel model = new DistributorModel(_unitOfWork);
                if (ModelState.IsValid)
                {
                    await model.SaveAsync(record);

                    logger.Debug("Distributor saved successfully.");
                    return(Json(new { result = true }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new { result = false }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception ex)
            {
                logger.Error("Error while invoking Save action method: ", ex);
                return(Json(new { result = false, error = ex.Message }, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult CreateContract(ContractDistributorVM model, [Bind(Prefix = "ContractViewModel")] ContractViewModel con, [Bind(Prefix = "DistributorViewModel")] DistributorViewModel dis, [Bind(Prefix = "RepresentativeViewModel")] RepresentativeViewModel rep)
        {
            isAdminLogged();
            logger.Info("Start controller to create contract...");
            var  user = Session["admin"] as Account;
            bool result;
            var  _con = new Contract();

            _con.area               = con.area;
            _con.beginDate          = con.beginDate;
            _con.commission         = con.commission;
            _con.disType            = con.disType;
            _con.expiredDate        = con.expiredDate;
            _con.maxDebt            = con.maxDebt;
            _con.minOrderTotalValue = con.minOrderTotalValue;
            _con.note               = con.note;
            _con.staff              = staff_Service.GetByAccount(user.UserName).idStaff;

            if (rep.idRepresentative == 0)  // Create contract for old distributor
            {
                Representative _rep = new Representative
                {
                    idRepresentative = rep_Service.GenerateRepresentativeId(),
                    name             = rep.name,
                    title            = rep.title,
                    phone            = rep.phone,
                    email            = rep.email,
                    Distributor      = dis.idDistributor
                };
                _con.Representative1 = _rep;
                _con.distributor     = dis.idDistributor;
                result = con_Service.CreateContract(_con, false);
            }
            else        // Create contract for potential distributor
            {
                Distributor _dis = new Distributor
                {
                    idDistributor = dis_Service.GenerateDistributorId(),
                    name          = dis.name,
                    address       = dis.address,
                    Email         = dis.Email,
                    phone         = dis.phone,
                    createdDate   = DateTime.Now,
                    updatedDate   = DateTime.Now,
                    debt          = 0,
                    status        = true
                };
                _con.Distributor1   = _dis; // _dis.idDistributor;
                _con.representative = rep.idRepresentative;
                result = con_Service.CreateContract(_con, true);
                //pDis_Service.UpdateStatus(dis.idDistributor, 5, "Đã tạo hợp đồng");
            }
            if (result == true)
            {
                TempData["success"] = "Thành công";
                model = new ContractDistributorVM();
                logger.Info("End: Successful....");
            }
            else
            {
                TempData["fail"] = "Thất bại";
                logger.Info("End: Unsuccessful....");
            }

            return(RedirectToAction("CreateContract"));
        }
コード例 #20
0
        public IActionResult GetDistributorView(string token)
        {
            string          baseUrl         = repository.GetKeyValue("BMGBaseUrl");// "https://webservice.bevmedia.com/BMGOrderWebService/api";
            ErrorModel      errorModel      = new ErrorModel();
            BevMediaService bevMediaService = new BevMediaService(baseUrl);
            TokenInfo       tokenInfo       = bevMediaService.VerifyToken(token, out var err);

            if (string.IsNullOrWhiteSpace(err))
            {
                DistributorInfo distributor = bevMediaService.GetDistributorInfo(tokenInfo, out var errMsg);
                //RetailerInfo distributor = bevMediaService.GetRetailerInfo(tokenInfo, out var errMsg);
                if (string.IsNullOrWhiteSpace(errMsg))
                {
                    var creditDataList = _context.CreditData
                                         .Where(x => x.DistributorId == tokenInfo.DistributorID)
                                         .Include(files => files.CreditDataFiles)
                                         .ToList();
                    var ws = new AdobeSignWS();
                    foreach (var creditDataEntity in creditDataList)
                    {
                        if (creditDataEntity.Status == CreditAppStatusEnum.OUT_FOR_SIGNATURE.ToString())
                        {
                            var agreement = ws.GetAgreement(creditDataEntity.AdobeSignAgreementId, creditDataEntity.Id.Value);
                            if (agreement.status != creditDataEntity.Status)
                            {
                                creditDataEntity.Status = agreement.status;
                                _context.SaveChanges();
                            }
                        }
                    }
                    var           creditDataListModel = _mapper.Map <List <CreditData> >(creditDataList);
                    List <string> acceptedStatuses    = new List <string> {
                        CreditAppStatusEnum.OUT_FOR_SIGNATURE.ToString(),
                                  CreditAppStatusEnum.SIGNED.ToString(),
                                  CreditAppStatusEnum.APPROVED.ToString(),
                                  CreditAppStatusEnum.DENIED.ToString(),
                    };
                    List <string> editStatuses = new List <string> {
                        CreditAppStatusEnum.SIGNED.ToString(),
                                  CreditAppStatusEnum.APPROVED.ToString(),
                                  CreditAppStatusEnum.DENIED.ToString(),
                    };
                    foreach (var item in creditDataListModel)
                    {
                        if (acceptedStatuses.Contains(item.Status))
                        {
                            item.DistributorStatus = item.Status;
                        }
                        else
                        {
                            item.DistributorStatus = CreditAppStatusEnum.IN_PROGRESS.ToString();
                        }
                        if (editStatuses.Contains(item.Status))
                        {
                            item.CanAddComments = true;
                        }
                    }
                    var distributorViewModel = new DistributorViewModel();
                    distributorViewModel.CreditDataList = creditDataListModel;

                    distributorViewModel.Distributor = new Distributor();
                    distributorViewModel.Distributor.DistributorLogoURL = distributor.DistributorLogoURL;
                    distributorViewModel.Distributor.DistributorName    = distributor.DistributorName;

                    return(View("DistributorView", distributorViewModel));
                }
                else
                {
                    errorModel.Message = errMsg;
                }
            }
            else
            {
                errorModel.Message = err;
            }
            return(View("ErrorView", errorModel));
        }
コード例 #21
0
ファイル: ClientController.cs プロジェクト: aspineon/ccc
        public ActionResult VisitDetails(int id)
        {
            @ViewBag.YesNo = new List <string>()
            {
                "Brak danych",
                "Tak",
                "Nie",
                "Nie dotyczy"
            };

            var visitDetails = new VisitDetailsViewModel();

            @ViewBag.Provinces = context.Provinces.ToList();
            @ViewBag.Districts = context.Districts.ToList();

            var visit = context.Visits.SingleOrDefault(v => v.Id == id);

            if (visit == null)
            {
                return(HttpNotFound());
            }
            var data = context.BusinessDatas.Single(d => d.BusinessId == visit.BusinessId);

            visitDetails.Data = Utils.ClientData.GetClientDetails(data, context);

            var step1   = context.ClientSteps1.OrderByDescending(c => c.Id).FirstOrDefault(c => c.VisitId == id);
            var step2   = context.ClientSteps2.Include(s => s.Assortment).Include(s => s.Assortment.Package).Include(s => s.Assortment.PartOfCement).OrderByDescending(c => c.Id).FirstOrDefault(c => c.VisitId == id);
            var step3   = context.ClientSteps3.Include(s => s.Manufacturers).Include(s => s.ManufacturersGroups).Include(s => s.Suppliers).OrderByDescending(c => c.Id).FirstOrDefault(c => c.VisitId == id);
            var step3_5 = context.ClientSteps3_5.Include(s => s.Distributors).Include(s => s.Manufacturers).Include(s => s.ManufacturersGroups).OrderByDescending(c => c.Id).FirstOrDefault(c => c.VisitId == id);
            var step4   = context.ClientSteps4.OrderByDescending(c => c.Id).FirstOrDefault(c => c.VisitId == id);
            var step5   = context.ClientSteps5.OrderByDescending(c => c.Id).FirstOrDefault(c => c.VisitId == id);
            var step7   = context.ClientSteps7.Include(s => s.LaxTypes).Include(s => s.PackedTypes).OrderByDescending(c => c.Id).FirstOrDefault(c => c.VisitId == id);

            visitDetails.VisitId           = visit.Id;
            visitDetails.MainMarketSegment = context.MarketSegments.SingleOrDefault(m => m.Id == visit.MainMarketSegmentId).Name;
            visitDetails.VisitDate         = visit.VisitDate.ToString("yyyy-MM-dd");
            visitDetails.VisitComments     = visit.Comments;
            if (step1 != null)
            {
                foreach (var ms in step1.VisitMarketSegments)
                {
                    if (ms.MarketSegmentId != 0)
                    {
                        ms.MarketSegment = context.MarketSegments.Single(s => s.Id == ms.MarketSegmentId);
                    }
                }
                visitDetails.MarketSegments = step1.VisitMarketSegments;
                visitDetails.Branches       = step1.Branches;
            }
            if (step2 != null)
            {
                visitDetails.Assortment = step2.Assortment;
                if (step2.LaxTypes != null)
                {
                    foreach (VisitLaxType t in step2.LaxTypes)
                    {
                        if (t.Id != 0)
                        {
                            t.LaxType = context.LaxCementTypes.Single(p => p.Id == t.LaxTypeId);
                        }
                    }
                    visitDetails.VisitLaxTypes = step2.LaxTypes;
                }
                if (step2.PackedTypes != null)
                {
                    foreach (VisitPackedType t in step2.PackedTypes)
                    {
                        if (t.PackedTypeId != 0)
                        {
                            t.PackedType = context.PackedCementTypes.Single(p => p.Id == t.PackedTypeId);
                        }
                    }
                    visitDetails.VisitPackedTypes = step2.PackedTypes;
                }
            }
            if (step4 != null)
            {
                visitDetails.Logistic    = step4.Logistic;
                visitDetails.UnloadTypes = new List <string>();
                foreach (VisitUnloadType t in step4.UnloadTypes)
                {
                    if (t.UnloadTypeId != 0)
                    {
                        var type = context.UnloadTypes.Single(u => u.Id == t.UnloadTypeId).Name;
                        visitDetails.UnloadTypes.Add(type);
                    }
                }
            }
            if (step5 != null)
            {
                visitDetails.Clients = new List <KeyValuePair <string, int> >();
                foreach (VisitClients c in step5.Clients)
                {
                    if (c.ClientId != 0)
                    {
                        var client = context.Clients.Single(v => v.Id == c.ClientId);
                        var cl     = new KeyValuePair <string, int>(client.Name, c.Percent);
                        visitDetails.Clients.Add(cl);
                    }
                }
            }
            if (step7 != null)
            {
                visitDetails.LaxPrices = new List <ViewPrice>();
                if (step7.LaxTypes != null)
                {
                    foreach (ClientLax c in step7.LaxTypes)
                    {
                        var price = new ViewPrice();
                        price.Buy  = c.BuyPrice;
                        price.Sell = c.SellPrice;
                        if (c.PriceType == 1)
                        {
                            price.Type = "Brak danych";
                        }
                        if (c.PriceType == 2)
                        {
                            price.Type = "Loco";
                        }
                        if (c.PriceType == 3)
                        {
                            price.Type = "Franco";
                        }
                        if (c.CementId != 0)
                        {
                            price.Name = context.LaxCementTypes.Single(t => t.Id == c.CementId).Name;
                        }
                        visitDetails.LaxPrices.Add(price);
                    }
                }
                visitDetails.PackedPrices = new List <ViewPrice>();
                if (step7.PackedTypes != null)
                {
                    foreach (ClientPacked c in step7.PackedTypes)
                    {
                        var price = new ViewPrice();
                        price.Buy  = c.BuyPrice;
                        price.Sell = c.SellPrice;
                        if (c.PriceType == 1)
                        {
                            price.Type = "Brak danych";
                        }
                        if (c.PriceType == 2)
                        {
                            price.Type = "Loco";
                        }
                        if (c.PriceType == 3)
                        {
                            price.Type = "Franco";
                        }
                        if (c.CementId != 0)
                        {
                            price.Name = context.PackedCementTypes.Single(t => t.Id == c.CementId).Name;
                        }
                        visitDetails.PackedPrices.Add(price);
                    }
                }
            }
            if (step3 != null)
            {
                visitDetails.Cooperation = step3.Cooperation;
                visitDetails.Suppliers   = new List <ViewSupplier>();
                if (step3.Suppliers != null && step3.Cooperation)
                {
                    foreach (VisitSupplier s in step3.Suppliers)
                    {
                        var sup = new ViewSupplier();
                        if (s.SupplierId != 0)
                        {
                            sup.Name = context.Suppliers.Single(ss => ss.Id == s.SupplierId).Name;
                        }
                        sup.Text = s.Text;
                        visitDetails.Suppliers.Add(sup);
                    }
                }

                visitDetails.Step3Manufs = new List <ViewManufacturer>();
                if (step3.Manufacturers != null)
                {
                    foreach (VisitManufacturers s in step3.Manufacturers)
                    {
                        if (s.GroupId == 0)
                        {
                            var sup = new ViewManufacturer();
                            if (s.ManufacturerId != 0)
                            {
                                sup.Name = context.Manufacturers.Single(ss => ss.Id == s.ManufacturerId).Name;
                            }
                            sup.Percent = s.Percent;
                            visitDetails.Step3Manufs.Add(sup);
                        }
                    }
                }

                visitDetails.Step3ManufsGroups = new List <ViewManGroup>();
                if (step3.ManufacturersGroups != null)
                {
                    foreach (VisitManufacturersGroup g in step3.ManufacturersGroups)
                    {
                        var gr = new ViewManGroup();
                        if (g.ManufacturersGroupId != 0)
                        {
                            gr.Name = context.ManufacturersGroups.Single(a => a.Id == g.ManufacturersGroupId).Name;
                        }
                        gr.Percent       = step3.Manufacturers.Any(m => m.GroupId == g.ManufacturersGroupId) ? 0 : g.Percent;
                        gr.Manufacturers = new List <ViewManufacturer>();
                        foreach (VisitManufacturers s in step3.Manufacturers)
                        {
                            if (s.GroupId == g.ManufacturersGroupId)
                            {
                                var sup = new ViewManufacturer();
                                if (s.ManufacturerId != 0)
                                {
                                    sup.Name = context.Manufacturers.Single(ss => ss.Id == s.ManufacturerId).Name;
                                }
                                sup.Percent = s.Percent;
                                gr.Percent += s.Percent;
                                gr.Manufacturers.Add(sup);
                            }
                        }
                        visitDetails.Step3ManufsGroups.Add(gr);
                    }
                }
            }
            if (step3_5 != null)
            {
                if (step3_5.ReceiptId != 0)
                {
                    visitDetails.RecType = context.Receipts.Single(r => r.Id == step3_5.ReceiptId).Name;
                }

                visitDetails.Manufs = new List <ViewManufacturer>();
                if (step3_5.Manufacturers != null)
                {
                    foreach (VisitManufacturers s in step3_5.Manufacturers)
                    {
                        if (s.GroupId == 0)
                        {
                            var sup = new ViewManufacturer();
                            if (s.ManufacturerId != 0)
                            {
                                sup.Name = context.Manufacturers.Single(ss => ss.Id == s.ManufacturerId).Name;
                            }
                            sup.Percent = s.Percent;
                            visitDetails.Manufs.Add(sup);
                        }
                    }
                }

                visitDetails.ManGroups = new List <ViewManGroup>();
                if (step3_5.ManufacturersGroups != null)
                {
                    foreach (VisitManufacturersGroup g in step3_5.ManufacturersGroups)
                    {
                        var gr = new ViewManGroup();
                        if (g.ManufacturersGroupId != 0)
                        {
                            gr.Name = context.ManufacturersGroups.Single(a => a.Id == g.ManufacturersGroupId).Name;
                        }
                        gr.Percent       = g.Percent;
                        gr.Manufacturers = new List <ViewManufacturer>();
                        foreach (VisitManufacturers s in step3_5.Manufacturers)
                        {
                            if (s.GroupId == g.ManufacturersGroupId)
                            {
                                var sup = new ViewManufacturer();
                                if (s.ManufacturerId != 0)
                                {
                                    sup.Name = context.Manufacturers.Single(ss => ss.Id == s.ManufacturerId).Name;
                                }
                                sup.Percent = s.Percent;
                                gr.Manufacturers.Add(sup);
                            }
                        }
                        visitDetails.ManGroups.Add(gr);
                    }
                }
                if (step3_5.Distributors != null)
                {
                    visitDetails.Distributors = new List <DistributorViewModel>();
                    foreach (VisitDistributor d in step3_5.Distributors)
                    {
                        var dist = new DistributorViewModel();
                        dist.IsMarket = false;
                        if (d.DistributorId != 0)
                        {
                            var dd = context.Distributors.Single(dis => dis.Id == d.DistributorId);
                            dist.Name     = dd.Name;
                            dist.IsMarket = dd.IsMarket;
                            if (dd.IsMarket && d.MarketAddressId != null && d.MarketAddressId > 0)
                            {
                                dist.Address = d.MarketAddress;
                            }
                        }
                        dist.Percent = d.Percent;
                        if (d.Manufacturers != null)
                        {
                            dist.Manufacturers = new List <ViewManufacturer>();
                            foreach (VisitDistManufacturer m in d.Manufacturers)
                            {
                                var man = new ViewManufacturer();
                                if (m.ManufacturerId != 0)
                                {
                                    man.Name = context.Manufacturers.Single(mm => mm.Id == m.ManufacturerId).Name;
                                }
                                man.Percent = m.Percent;
                                dist.Manufacturers.Add(man);
                            }
                        }
                        if (d.ManufacturersGroups != null)
                        {
                            dist.Groups = new List <ViewManGroup>();
                            foreach (VisitDistManufacturersGroup g in d.ManufacturersGroups)
                            {
                                var gr = new ViewManGroup();
                                if (g.ManufacturersGroupId != 0)
                                {
                                    gr.Name = context.ManufacturersGroups.Single(gg => gg.Id == g.ManufacturersGroupId).Name;
                                }
                                gr.Percent = g.Percent;
                                if (g.Mans != null && g.Mans.Count > 0)
                                {
                                    gr.Percent       = 0;
                                    gr.Manufacturers = new List <ViewManufacturer>();
                                    foreach (var gm in g.Mans)
                                    {
                                        var vm = new ViewManufacturer();
                                        if (gm.ManufacturerId != 0)
                                        {
                                            vm.Name = context.Manufacturers.Single(mm => mm.Id == gm.ManufacturerId).Name;
                                        }
                                        vm.Percent  = gm.Percent;
                                        gr.Percent += gm.Percent;
                                        gr.Manufacturers.Add(vm);
                                    }
                                }
                                dist.Groups.Add(gr);
                            }
                        }
                        visitDetails.Distributors.Add(dist);
                    }
                }
            }
            visitDetails.Step4 = step4;
            visitDetails.Step5 = step5;
            visitDetails.Step6 = context.ClientSteps6.OrderByDescending(c => c.Id).FirstOrDefault(c => c.VisitId == id);
            visitDetails.Step7 = step7;
            visitDetails.Step8 = context.ClientSteps8.OrderByDescending(c => c.Id).FirstOrDefault(c => c.VisitId == id);
            return(View(visitDetails));
        }
コード例 #22
0
 public static Distributor ToEntity(this DistributorViewModel model)
 {
     return(model.MapTo <DistributorViewModel, Distributor>());
 }
コード例 #23
0
 public static Distributor ToEntity(this DistributorViewModel model, Distributor entity)
 {
     return(model.MapTo(entity));
 }