Beispiel #1
0
        public ActionResult Insert(MPromo viewModel, FormCollection formCollection)
        {
            if (!(ViewData.ModelState.IsValid && viewModel.IsValid()))
            {
            }
            MPromo mCompanyToInsert = new MPromo();

            TransferFormValuesTo(mCompanyToInsert, viewModel);
            UpdateNumericData(mCompanyToInsert, formCollection);
            mCompanyToInsert.SetAssignedIdTo(viewModel.Id);
            mCompanyToInsert.CreatedDate = DateTime.Now;
            mCompanyToInsert.CreatedBy   = User.Identity.Name;
            mCompanyToInsert.DataStatus  = EnumDataStatus.New.ToString();
            _mPromoRepository.Save(mCompanyToInsert);

            try
            {
                _mPromoRepository.DbContext.CommitChanges();
            }
            catch (Exception e)
            {
                _mPromoRepository.DbContext.RollbackTransaction();

                //throw e.GetBaseException();
                return(Content(e.GetBaseException().Message));
            }

            return(Content("success"));
        }
Beispiel #2
0
 private void TransferFormValuesTo(MPromo mCompanyToUpdate, MPromo mCompanyFromForm)
 {
     mCompanyToUpdate.PromoName      = mCompanyFromForm.PromoName;
     mCompanyToUpdate.PromoDesc      = mCompanyFromForm.PromoDesc;
     mCompanyToUpdate.PromoStartDate = mCompanyFromForm.PromoStartDate;
     mCompanyToUpdate.PromoEndDate   = mCompanyFromForm.PromoEndDate;
 }
Beispiel #3
0
 private static void UpdateNumericData(MPromo promo, FormCollection formCollection)
 {
     if (!string.IsNullOrEmpty(formCollection["PromoValue"]))
     {
         string PromoValue = formCollection["PromoValue"].Replace(",", "");
         promo.PromoValue = Convert.ToDecimal(PromoValue);
     }
     else
     {
         promo.PromoValue = null;
     }
 }
Beispiel #4
0
        public ActionResult Delete(MPromo viewModel, FormCollection formCollection)
        {
            MPromo mCompanyToDelete = _mPromoRepository.Get(viewModel.Id);

            if (mCompanyToDelete != null)
            {
                _mPromoRepository.Delete(mCompanyToDelete);
            }

            try
            {
                _mPromoRepository.DbContext.CommitChanges();
            }
            catch (Exception e)
            {
                _mPromoRepository.DbContext.RollbackTransaction();

                return(Content(e.GetBaseException().Message));
            }

            return(Content("success"));
        }
Beispiel #5
0
        public ActionResult Update(MPromo viewModel, FormCollection formCollection)
        {
            MPromo mCompanyToUpdate = _mPromoRepository.Get(viewModel.Id);

            TransferFormValuesTo(mCompanyToUpdate, viewModel);
            UpdateNumericData(mCompanyToUpdate, formCollection);
            mCompanyToUpdate.ModifiedDate = DateTime.Now;
            mCompanyToUpdate.ModifiedBy   = User.Identity.Name;
            mCompanyToUpdate.DataStatus   = EnumDataStatus.Updated.ToString();
            _mPromoRepository.Update(mCompanyToUpdate);

            try
            {
                _mPromoRepository.DbContext.CommitChanges();
            }
            catch (Exception e)
            {
                _mPromoRepository.DbContext.RollbackTransaction();

                return(Content(e.GetBaseException().Message));
            }

            return(Content("success"));
        }
        private ActionResult SaveTransRoom(TTrans Trans, FormCollection formCollection)
        {
            _tTransRepository.DbContext.BeginTransaction();
            if (Trans == null)
            {
                Trans = new TTrans();
            }
            Trans.SetAssignedIdTo(formCollection["TransId"]);
            Trans.TransStatus = EnumTransactionStatus.Service.ToString();
            if (!string.IsNullOrEmpty(formCollection["TransDiscount"]))
            {
                string TransDiscount = formCollection["TransDiscount"].Replace(",", "");
                Trans.TransDiscount = Convert.ToDecimal(TransDiscount);
            }
            //get promo
            MPromo  promo      = _mPromoRepository.GetActivePromoByDate(DateTime.Today);
            string  promoName  = string.Empty;
            decimal promoValue = 0;

            if (promo != null)
            {
                Trans.PromoId    = promo;
                Trans.PromoValue = promo.PromoValue;

                promoName  = promo.PromoName;
                promoValue = promo.PromoValue ?? 0;
            }

            //Trans.TransDate = DateTime.Today;
            Trans.CreatedDate = DateTime.Now;
            Trans.CreatedBy   = User.Identity.Name;
            Trans.DataStatus  = Enums.EnumDataStatus.New.ToString();



            _tTransRepository.Save(Trans);


            TTransRoom troom = new TTransRoom();

            troom.SetAssignedIdTo(Trans.Id);
            if (!string.IsNullOrEmpty(formCollection["RoomInDate"]))
            {
                troom.RoomInDate = Convert.ToDateTime(string.Format("{0:dd-MMM-yyyy} {1}", Trans.TransDate, formCollection["RoomInDate"]));
            }
            if (!string.IsNullOrEmpty(formCollection["RoomOutDate"]))
            {
                troom.RoomOutDate = Convert.ToDateTime(string.Format("{0:dd-MMM-yyyy} {1}", Trans.TransDate, formCollection["RoomOutDate"]));
            }
            troom.RoomStatus = EnumTransRoomStatus.In.ToString();
            if (!string.IsNullOrEmpty(formCollection["RoomId"]))
            {
                troom.RoomId = _mRoomRepository.Get(formCollection["RoomId"]);
            }
            troom.CreatedDate = DateTime.Now;
            troom.CreatedBy   = User.Identity.Name;
            troom.DataStatus  = EnumDataStatus.New.ToString();

            _tTransRoomRepository.Save(troom);

            string Message = string.Empty;
            bool   Success = true;

            try
            {
                _tTransRepository.DbContext.CommitTransaction();
                TempData[EnumCommonViewData.SaveState.ToString()] = EnumSaveState.Success;
            }
            catch (Exception ex)
            {
                Success = false;
                Message = ex.GetBaseException().Message;
                _tTransRepository.DbContext.RollbackTransaction();
                TempData[EnumCommonViewData.SaveState.ToString()] = EnumSaveState.Failed;
            }
            var e = new
            {
                Success,
                Message,
                RoomStatus = EnumTransRoomStatus.In.ToString(),
                PromoName  = promoName + "(%)",
                PromoValue = promoValue
            };

            return(Json(e, JsonRequestBehavior.AllowGet));
            //return View("Status");
        }