//GET: Admin/PaymentManager/Create
        public ActionResult Create()
        {
            this.StatusList(1);
            this.Pair2List <PaymentTypesEditViewModel, short, short>(PaymentListProvider.GetMethods(), m => m.Method, null);
            this.Pair2List <PaymentTypesEditViewModel, string, string>(m_posWorker.GetPosForList(), m => m.PosType, "");
            var model = new PaymentTypesEditViewModel
            {
                Status = 1
            };

            return(View(model));
        }
Exemplo n.º 2
0
        public void InsertManagerPaymentTypesEdit(PaymentTypesEditViewModel model)
        {
            var item = Mapper.Map <Payment_Types>(model);

            m_ContentContext.Payment_Types.Add(item);
            m_ContentContext.SaveChanges();
            foreach (var modelInst in model.PaymentInstallments)
            {
                var itemInst = Mapper.Map <Payment_Installment>(modelInst);
                itemInst.PaymentId = item.Id;
                m_ContentContext.Payment_Installment.Add(itemInst);
            }
            m_ContentContext.SaveChanges();
        }
 public ActionResult Create(PaymentTypesEditViewModel model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             m_paymentWorker.InsertManagerPaymentTypesEdit(model);
             return(RedirectToAction("Index"));
         }
         catch (Exception ex)
         {
             ModelState.AddModelError("General", ex.Message);
         }
     }
     this.StatusList(model.Status);
     this.Pair2List <PaymentTypesEditViewModel, short, short>(PaymentListProvider.GetMethods(), m => m.Method, model.Method.ToString());
     return(View(model));
 }
Exemplo n.º 4
0
        public void UpdateManagerPaymentTypesEdit(PaymentTypesEditViewModel model)
        {
            var query = from p in m_ContentContext.Payment_Types
                        where p.Id == model.Id
                        select p;
            var item = query.FirstOrDefault();

            Mapper.Map(model, item);
            if (model.PaymentInstallments == null)
            {
                foreach (var itemPayment in item.Payment_Installment)
                {
                    m_ContentContext.Payment_Installment.Remove(itemPayment);
                }
            }
            else
            {
                foreach (var modelInst in model.PaymentInstallments)
                {
                    var itemInst = item.Payment_Installment.FirstOrDefault(f => f.Id == modelInst.Id);
                    if (itemInst == null)
                    {
                        itemInst           = Mapper.Map <Payment_Installment>(modelInst);
                        itemInst.PaymentId = item.Id;
                        m_ContentContext.Payment_Installment.Add(itemInst);
                    }
                    else
                    {
                        Mapper.Map(modelInst, itemInst);
                    }
                }
                var deleteList      = item.Payment_Installment.Where(w => !model.PaymentInstallments.Select(s => s.Id).Contains(w.Id)).ToList();
                int deleteListCount = deleteList.Count;
                for (int i = 0; i < deleteListCount; i++)
                {
                    m_ContentContext.Payment_Installment.Remove(deleteList[0]);
                }
            }
            m_ContentContext.SaveChanges();
        }