public ActionResult Create(PromotionViewModel km)
        {
            ViewBag.message = "";
            if (ModelState.IsValid)
            {
                KHUYENMAI khuyenmai = new KHUYENMAI();
                khuyenmai.MAKM   = km.MAKM;
                khuyenmai.TENKM  = km.TENKM;
                khuyenmai.NGAYBD = km.NGAYBD;
                khuyenmai.NGAYKT = km.NGAYKT;

                if (promotionService.addPromotion(khuyenmai))
                {
                    ViewBag.message = "Thêm mới khuyến mãi thành công";
                    km      = new PromotionViewModel();
                    km.MAKM = newMAKM(promotionService.getLastRecord());
                    return(View(km));
                }
                else
                {
                    ViewBag.message = "Thêm mới khuyến mãi thất bại";
                }
            }
            return(View(km));
        }
        public IHttpActionResult PostStudentsByClIdandGrpId(PromotionViewModel st)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Invalid data."));
            }

            IList <StudentViewModel> lss = null;

            using (var ctx = new EMSEntities())
            {
                lss = ctx.spStudentCurrentClass((double)st.CLASS_TRNNO, st.GRPMST_TRNNO)
                      .Select(s => new StudentViewModel()
                {
                    TRNNO      = s.TRNNO,
                    EMP_ID     = s.EMP_ID,
                    EMP_F_NAME = s.EMP_F_NAME,
                    EMP_NAME   = s.EMP_NAME
                }).ToList <StudentViewModel>();
            }

            if (lss == null)
            {
                return(NotFound());
            }

            return(Ok(lss));
        }
        public IHttpActionResult GetFeeCollectById(int id)
        {
            PromotionViewModel fcs = null;

            using (var ctx = new EMSEntities())
            {
                fcs = ctx.PROMMSTs
                      .Where(s => s.TRNNO == id)
                      .Select(s => new PromotionViewModel()
                {
                    TRNNO        = s.TRNNO,
                    PDT          = s.PDT,
                    FCLASS_TRNNO = s.FCLASS_TRNNO,
                    GRPMST_TRNNO = s.GRPMST_TRNNO,
                    CLASS_TRNNO  = s.CLASS_TRNNO,
                    SECDTL_TRNNO = s.SECDTL_TRNNO,
                    SECDTL_SR    = s.SECDTL_SR,
                }).FirstOrDefault <PromotionViewModel>();
            }

            if (fcs == null)
            {
                return(NotFound());
            }

            return(Ok(fcs));
        }
Esempio n. 4
0
        //View Approve
        public ActionResult Approve(int id)
        {
            PromotionViewModel model = PromotionRepo.GetById(id);

            ViewBag.Employee = new SelectList(PromotionRepo.GetStaff(), "Id", "Full_Name");
            UserViewModel currentuser = PromotionRepo.GetIdByName(User.Identity.Name);

            if (model.FlagDesign == "Yes")
            {
                return(PartialView("_Approve", model));
            }
            else
            {
                return(PartialView("_ApproveNo", model));
            }

            if (currentuser.Role == "Admin")
            {
                ViewBag.Employee = new SelectList(EmployeeRepo.Get(), "Id", "FullName");
                return(PartialView("_Approve", PromotionRepo.GetById(id)));
            }
            else
            {
                return(new RedirectToRouteResult(new RouteValueDictionary(new { controller = "AccessDenied", action = "Index" })));
            }
        }
Esempio n. 5
0
        public PromotionViewModel GetActivePromotion(string promotionUrl)
        {
            var promotion          = _promotionManager.GetActivePromotion(promotionUrl);
            var promotionViewModel = new PromotionViewModel(promotion);

            return(promotionViewModel);
        }
Esempio n. 6
0
        //Ambil Id untuk Ubah status saat Approval
        public static ResultResponse Approve(PromotionViewModel entity)
        {
            ResultResponse result = new ResultResponse();

            try
            {
                using (var db = new MarComContext())
                {
                    T_Promotion pr = db.T_Promotion.Where(p => p.Id == entity.Id).FirstOrDefault();
                    if (pr != null)
                    {
                        pr.Reject_Reason = entity.Reject_Reason;
                        pr.Status        = entity.Status;
                        pr.Assign_To     = entity.Assign_To;
                        if (entity.Status == 2)
                        {
                            pr.Approved_By   = entity.Approved_By;
                            pr.Approved_Date = DateTime.Now;
                        }

                        db.SaveChanges();
                    }
                }
            }
            catch (Exception ex)
            {
                result.Success = false;
                result.Message = ex.Message;
            }
            return(result);
        }
        public ActionResult PromotionEditFromList(uint id)
        {
            var model = new PromotionViewModel();

            model.SetData(DbSession, id);
            return(View(model));
        }
        public ActionResult Add()
        {
            var model = new PromotionViewModel();

            ViewBag.addresses = _unitOfWork.Addresses.GetAllByUser(AppUser.Id);
            return(View(model));
        }
Esempio n. 9
0
 public ProductViewModel(PromotionViewModel promotion)
 {
     _productPromotion  = promotion;
     PromotionCreated   = _productPromotion.Created;
     PromotionLifetime  = _productPromotion.Lifetime;
     PriceWithPromotion = _productPromotion.Percent;
 }
Esempio n. 10
0
        public ActionResult Create(FormCollection formCollection, PromotionViewModel vo)
        {
            if (ModelState.IsValid)
            {
                var entity = MappingManager.PromotionEntityMapping(vo);
                entity.CreatedUser         = base.CurrentUser.CustomerId;
                entity.UpdatedUser         = base.CurrentUser.CustomerId;
                entity.RecommendSourceId   = CurrentUser.CustomerId;
                entity.RecommendSourceType = (int)RecommendSourceType.Default;
                entity.RecommendUser       = CurrentUser.CustomerId;
                entity.Status = (int)DataStatus.Default;
                entity.IsMain = true;
                using (TransactionScope ts = new TransactionScope())
                {
                    entity = this._promotionRepository.Insert(entity);
                    var ids = _resourceService.Save(ControllerContext.HttpContext.Request.Files
                                                    , CurrentUser.CustomerId
                                                    , -1, entity.Id
                                                    , SourceType.Promotion);
                    ts.Complete();
                }

                return(RedirectToAction("List"));
            }

            return(View(vo));
        }
        public JsonResult SavePromotion(PromotionViewModel promotionViewModel)
        {
            HttpResponseMessage response = new APIHelper.APICallMethod().GetHttpResponseMessage("SavePromotion", "AdminPanel", promotionViewModel);

            if (response.IsSuccessStatusCode)
            {
                var data = response.Content.ReadAsStringAsync().Result;
                ViewModel.ResponseModel.ResponseViewModel <Dictionary <string, bool> > dbBookingDetails = JsonConvert.DeserializeObject <ViewModel.ResponseModel.ResponseViewModel <Dictionary <string, bool> > >(data);
                if (dbBookingDetails.IdentityResult.Status == true)
                {
                    return(Json(new { code = 0, message = "Success" }));
                }
                else
                {
                    if (dbBookingDetails.IdentityResult.Message == "Invalid access details, Please log-out.")
                    {
                        return(Json(new { code = -99, message = "Please Login Again" }));
                    }
                    else
                    {
                        return(Json(new { code = -1, message = dbBookingDetails.IdentityResult.Message }));
                    }
                }
            }
            else
            {
                return(Json(new { code = -2, message = "failed" }));
            }
        }
        public ActionResult CreateBonusPromotionXlsx(PromotionViewModel viewModel)
        {
            ViewBag.ViewModel = viewModel;
            if (viewModel.KeyID != null)
            {
                viewModel.GroupID = viewModel.DecryptKeyValue();
            }

            var promotions = models.GetBonusPromotion();

            if (viewModel.GroupID.HasValue)
            {
                promotions = promotions.Where(g => g.GroupID == viewModel.GroupID);
            }

            IQueryable <PDQTask> items = models.GetTable <PDQTask>()
                                         .Join(models.GetTable <PDQQuestion>()
                                               .Join(promotions, q => q.GroupID, p => p.GroupID, (q, p) => q),
                                               t => t.QuestionID, q => q.QuestionID, (t, q) => t);

            DataTable table = new DataTable();

            table.Columns.Add(new DataColumn("學員姓名", typeof(String)));
            table.Columns.Add(new DataColumn("活動名稱", typeof(String)));
            table.Columns.Add(new DataColumn("獲得點數", typeof(int)));
            table.Columns.Add(new DataColumn("獲得日期", typeof(String)));

            foreach (var item in items)
            {
                var pdq    = item.PDQQuestion;
                var pdqExt = pdq.PDQQuestionExtension;
                var r      = table.NewRow();
                r[0] = $"{item.UserProfile.FullName()}";
                r[1] = pdq.PDQGroup.GroupName;
                r[2] = pdqExt.BonusPoint;
                r[3] = $"{item.TaskDate:yyyy/MM/dd}";

                table.Rows.Add(r);
            }

            Response.Clear();
            Response.ClearContent();
            Response.ClearHeaders();
            Response.AddHeader("Cache-control", "max-age=1");
            Response.ContentType = "application/vnd.ms-excel";
            Response.AddHeader("Content-Disposition", String.Format("attachment;filename=({1:yyyy-MM-dd HH-mm-ss}){0}", HttpUtility.UrlEncode("BonusPromotion.xlsx"), DateTime.Now));

            using (DataSet ds = new DataSet())
            {
                ds.Tables.Add(table);

                using (var xls = ds.ConvertToExcel())
                {
                    xls.Worksheets.ElementAt(0).Name = "活動方案明細表";
                    xls.SaveAs(Response.OutputStream);
                }
            }

            return(new EmptyResult());
        }
Esempio n. 13
0
        public ActionResult EditPromotion(PromotionViewModel model, IEnumerable <HttpPostedFileBase> pictures)
        {
            if (ModelState.IsValid)
            {
                Promotion promotion = new Promotion
                {
                    Id          = model.Id,
                    Title       = model.Title,
                    Description = model.Description,
                    Date        = DateTime.Today,
                    StartDate   = model.StartDate,
                    EndDate     = model.EndDate
                };
                if (pictures.FirstOrDefault() != null)
                {
                    foreach (var image in pictures)
                    {
                        string uniqueName = Guid.NewGuid() + Path.GetExtension(image.FileName);
                        string localPath  = Path.Combine(Server.MapPath($"~{WebConfigurationManager.AppSettings["ImagesFolder"]}"), uniqueName);

                        image.SaveAs(localPath);
                        promotion.Images.Add(new PromotionImage {
                            Path = uniqueName
                        });
                    }
                }
                UnitOfWork.Instance.PromotionRepository.Update(promotion);

                return(RedirectToAction("Index", "Promotion"));
            }
            return(RedirectToAction("EditPromotion", model.Id));
        }
        public ActionResult Create()
        {
            PromotionViewModel promotionViewModel = new PromotionViewModel();

            promotionViewModel.MAKM = newMAKM(promotionService.getLastRecord());
            return(View(promotionViewModel));
        }
        public ActionResult Index()
        {
            PromotionViewModel pvm = new PromotionViewModel();

            pvm.PromoDishes = repository.Dishes.Where(d => d.DishID == 1).ToList();
            return(View(pvm));
        }
        public async Task <IActionResult> CustomerViewPromotions([Bind("SearchTerm")] PromotionViewModel promotionModel)
        {
            if (promotionModel.SearchTerm != null)
            {
                List <Promotion> promotion = await _promotionService.Search(promotionModel.SearchTerm);

                if (promotion == null)
                {
                    ViewBag.SearchResult = "No results found";
                    return(View());
                }

                PromotionViewModel promotionViewModel = new PromotionViewModel {
                    Promotions = promotion
                };
                return(View(promotionViewModel));
            }

            List <Promotion> promotions = await _promotionService.GetAllPromotions();

            if (promotions == null || promotions.Count < 1)
            {
                //to return empty if no results returned
                ViewBag.SearchResult = "No promotions available";
                return(View());
            }

            // To show all promotions upon page load for the 1st time
            PromotionViewModel promotionsViewModel = new PromotionViewModel {
                Promotions = promotions
            };

            return(View(promotionsViewModel));
        }
Esempio n. 17
0
        public bool IsAvailableForCreate(PromotionViewModel model)
        {
            var existedPromotions = _promotionRepo.Gets()
                                    .Where(p => p.SalonId == model.SalonId && p.Status == (byte)PromotionEnum.NORMAL && p.EndTime <= model.EndTime && p.EndTime >= model.StartTime).Count();

            return((existedPromotions > 0) ? false : true);
        }
        public ActionResult UpdateBonusPromotionStatus(PromotionViewModel viewModel, bool?tryToDelete)
        {
            var item = loadPromotionItem(viewModel);

            if (item == null)
            {
                return(View("~/Views/Shared/JsAlert.cshtml", model: "活動方案資料錯誤!!"));
            }

            item.PDQQuestion.First().PDQQuestionExtension.Status = (int?)viewModel.Status;
            models.SubmitChanges();

            if (tryToDelete == true)
            {
                try
                {
                    models.ExecuteCommand("delete PDQGroup where GroupID = {0}", item.GroupID);
                    return(Json(new { result = true }));
                }
                catch (Exception ex)
                {
                    ApplicationLogging.CreateLogger <PromotionController>().LogError(ex, ex.Message);
                    return(Json(new { result = false, message = ex.Message }));
                }
            }
            else
            {
                return(Json(new { result = true }));
            }
        }
Esempio n. 19
0
        // GET: Promotion
        public ActionResult Index()
        {
            var promotion = new PromotionViewModel();

            using (var unitOfWork = new UnitOfWork())
            {
                var result = unitOfWork.GetPromotionDetailByUsername(User.Identity.Name);

                if (result != null)
                {
                    promotion = new PromotionViewModel()
                    {
                        PromotionId = result.PromotionId,
                        Description = result.Description,
                        EndDate     = result.EndDate,
                        Expertise   = result.Expertise,
                        Price       = result.Price,
                        StartDate   = result.StartDate
                    };
                    var resultTags = unitOfWork.GetPromotionTagsByPromotionId(promotion.PromotionId).Select(x => new TagViewModel()
                    {
                        Tag   = x.Tag,
                        TagId = x.TagId
                    }
                                                                                                            );

                    promotion.Tags = resultTags.ToList();
                }
                else
                {
                    return(RedirectToAction("Create"));
                }
            }
            return(View(promotion));
        }
Esempio n. 20
0
        public static PromotionViewModel GetById(int id)
        {
            PromotionViewModel result = new PromotionViewModel();

            using (var db = new MarComContext())
            {
                result = (from pr in db.T_Promotion
                          join ev in db.T_Event on pr.T_Event_Id equals ev.Id
                          // join de in db.T_Design on pr.T_Design_Id equals de.Id
                          //join de in db.T_Design on pr.T_Design_Id equals de.Id
                          join e in db.M_Employee on pr.Request_By equals e.Id
                          where pr.Id == id
                          select new PromotionViewModel
                {
                    Id = pr.Id,
                    Code = pr.Code,
                    Flag_Design = pr.Flag_Design,
                    Title = pr.Title,
                    T_Event_Id = pr.T_Event_Id,
                    EventCode = ev.Code,
                    T_Design_Id = pr.T_Design_Id,
                    //     DesignCode = de.Code,
                    //DesignCode = de.Code,
                    Request_By = pr.Request_By,
                    RequestBy = e.First_Name + " " + e.Last_Name,

                    Status = pr.Status,
                    Request_Date = pr.Request_Date,
                    Note = pr.Note
                }).FirstOrDefault();
            }
            return(result);
        }
        public ActionResult Edit(PromotionViewModel promotionVm, HttpPostedFileBase fileUpload, bool checkEditPoster = false)
        {
            if (ModelState.IsValid)
            {
                var result = (PromotionViewModel)TempData["promotionItem"];
                promotionVm.PromotionID     = result.PromotionID;
                promotionVm.CreatedDate     = result.CreatedDate;
                promotionVm.CreatedBy       = result.CreatedBy;
                promotionVm.UpdatedDate     = DateTime.Now;
                promotionVm.UpdatedBy       = result.UpdatedBy;
                promotionVm.MetaDescription = result.MetaDescription;
                promotionVm.MetaKeyword     = result.MetaKeyword;


                if (checkEditPoster)
                {
                    // Lưu hình ảnh vào thư mục ~/Content/Promotion
                    string pathImage    = string.Empty;
                    string filePathSave = string.Empty;
                    if (fileUpload == null)
                    {
                        filePathSave = "404.png";
                    }
                    else
                    {
                        filePathSave = Path.GetFileName(fileUpload.FileName);
                        pathImage    = Path.Combine(Server.MapPath("~/Content/Promotion"), filePathSave);
                        if (System.IO.File.Exists(pathImage))
                        {
                            //return RedirectToAction("Index", "Home");
                        }
                        else
                        {
                            filePathSave = fileUpload.FileName;
                        }
                    }
                    if (filePathSave != "404.png")
                    {
                        fileUpload.SaveAs(pathImage);
                    }
                    promotionVm.PromotionPoster = filePathSave;
                }
                else
                {
                    promotionVm.PromotionPoster = result.PromotionPoster;
                }


                Promotion promotionUpdate = new Promotion();
                promotionUpdate.UpdatePromotion(promotionVm);
                promotionUpdate.PromotionID = result.PromotionID;

                _promotionService.Update(promotionUpdate);
                _promotionService.SaveChanges();

                SetAlert("Sửa ưu đãi thành công", CommonConstrants.SUCCESS_ALERT);
                return(RedirectToAction("Index"));
            }
            return(View(promotionVm));
        }
Esempio n. 22
0
        public ActionResult Edit(int?Id)
        {
            var Promotion = PromotionRepository.GetPromotionById(Id.Value);

            if (Promotion != null && Promotion.IsDeleted != true)
            {
                var model = new PromotionViewModel();
                AutoMapper.Mapper.Map(Promotion, model);

                //if (model.CreatedUserId != Helpers.Common.CurrentUser.Id && Helpers.Common.CurrentUser.UserTypeId != 1)
                //{
                //    TempData["FailedMessage"] = "NotOwner";
                //    return RedirectToAction("Index");
                //}

                var detailList = PromotionRepository.GetAllPromotionDetailBy(model.Id).Select(x => new PromotionDetailViewModel
                {
                    Id           = x.Id,
                    IsAll        = x.IsAll,
                    IsDeleted    = false,
                    PercentValue = x.PercentValue,
                    ProductId    = x.ProductId,
                    CategoryCode = x.CategoryCode,
                    QuantityFor  = x.QuantityFor,
                    Type         = x.Type
                }).ToList();

                if (detailList.Count == 0)
                {
                    detailList.Add(new PromotionDetailViewModel()
                    {
                        QuantityFor = 1, PercentValue = 0
                    });
                }

                model.DetailList = detailList;


                var productList = ProductRepository.GetAllProduct()
                                  .Select(item => new ProductViewModel
                {
                    Code          = item.Code,
                    Barcode       = item.Barcode,
                    Name          = item.Name,
                    Id            = item.Id,
                    CategoryCode  = item.CategoryCode,
                    PriceOutbound = item.PriceOutbound,
                    Unit          = item.Unit,
                });
                ViewBag.productList = productList;

                return(View(model));
            }
            if (Request.UrlReferrer != null)
            {
                return(Redirect(Request.UrlReferrer.AbsoluteUri));
            }
            return(RedirectToAction("Index"));
        }
Esempio n. 23
0
        public ActionResult Create()
        {
            ViewBag.EventCode  = new SelectList(EventRepo.Get(), "id", "Code");
            ViewBag.DesignCode = new SelectList(DesignRequestRepo.Get(), "id", "Code");
            PromotionViewModel model = new PromotionViewModel();

            return(PartialView("_Create", model));
        }
Esempio n. 24
0
        public void UpdatePromotion(PromotionViewModel model)
        {
            var entity = this.Promotions.GetById(model.Id);

            Mapper.Map(model, entity);

            this.Promotions.Update(entity);
        }
        public async Task <IActionResult> UpdatePromotion(PromotionViewModel promotionViewModel)
        {
            Promotion promotion = promotionViewModel.PromotionDto;
            var       result    = await _promotionService.UpdatePromotionAsync(promotion);

            TempData["message"] = "Update Successfully";
            return(RedirectToAction("Promotion", new { promotionId = result.PromotionId }));
        }
        public ActionResult PromotionFromListSave(PromotionViewModel model)
        {
            var promotion = DbSession.Query <ProducerPromotion>().First(s => s.Id == model.Promotion.Id);

            promotion.SuppliersType = model.SuppliersType;
            promotion.UpdateProductsAndSuppliersByIds(DbSession, model.ProductsListToSetList, model.SuppliersListToSetList);

            return(RedirectToAction("PromotionList", new { id = promotion.MarketingEvent.Id }));
        }
        public async Task <IActionResult> Register()
        {
            var message = TempData["message"];
            PromotionViewModel promotionViewModel = new PromotionViewModel {
                Message = message?.ToString() ?? string.Empty
            };

            return(View("AddPromotion", promotionViewModel));
        }
        public PromotionPage()
        {
            InitializeComponent();
            //LV.ItemTemplate = new DataTemplate(typeof(Cells.FurnitureCells.ProductViewCell));

            this.BindingContext             = viewModel = new PromotionViewModel();
            ModalUpdate.Body.BindingContext = viewModel;
            Init();
        }
        public ActionResult Create(PromotionViewModel promotionVm, HttpPostedFileBase fileUpload)
        {
            string pathImage = string.Empty;

            //kiểm tra và thêm dữ liệu vào database
            if (ModelState.IsValid)
            {
                string filePathSave = string.Empty;
                //check image resource
                if (fileUpload == null)
                {
                    //đặt đường dẫn ảnh mặc định
                    filePathSave = "404.png";
                }
                else
                {
                    filePathSave = Path.GetFileName(fileUpload.FileName);
                    pathImage    = Path.Combine(Server.MapPath("~/Content/Promotion"), filePathSave);
                    if (System.IO.File.Exists(pathImage))
                    {
                        //Hình ảnh đã tồn tại
                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        //Lưu tên file sẽ insert vào
                        filePathSave = fileUpload.FileName;
                    }
                }
                //update model từ view lên controller
                //cập nhật thời gian, tên ảnh, người thực hiện, mã của sản phẩm - thiếu người thực hiện
                promotionVm.PromotionPoster = filePathSave;

                promotionVm.CreatedDate = DateTime.Now;
                Promotion result = new Promotion();
                result.UpdatePromotion(promotionVm);
                var resultPromotion = _promotionService.Add(result);
                if (resultPromotion == null)
                {
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    if (filePathSave != "404.png")
                    {
                        fileUpload.SaveAs(pathImage);
                    }
                    _promotionService.SaveChanges();

                    SetAlert("Thêm ưu đãi thành công!", CommonConstrants.SUCCESS_ALERT);
                    return(RedirectToAction("Index", "Promotion"));
                }
            }
            ViewBag.PromotionStatusID = new SelectList(_statusService.GetAll(), "StatusID", "StatusName");
            return(View(promotionVm));
        }
        public async Task <IActionResult> GetPromotion(string id)
        {
            Promotion promotion = await _promotionService.RetrievePromotionAsync(Convert.ToInt32(id));

            PromotionViewModel promotionViewModel = new PromotionViewModel {
                PromotionDto = promotion
            };

            return(View("Index", promotionViewModel));
        }