示例#1
0
        public HttpResponseMessage AddModuleVoucher(HttpRequestMessage request)
        {
            return(CreateHttpResponse(request, () =>
            {
                HttpResponseMessage response = null;
                var mdVoucherJson = HttpContext.Current.Request.Unvalidated.Form["mdVoucher"];
                if (mdVoucherJson == null)
                {
                    response = request.CreateErrorResponse(HttpStatusCode.BadRequest, "Vui lòng cung cấp dữ liệu.");
                    return response;
                }
                var mdVoucherVm = new JavaScriptSerializer {
                    MaxJsonLength = Int32.MaxValue, RecursionLimit = 100
                }.Deserialize <MdVoucher>(mdVoucherJson);

                MdVoucher mdVoucherDb = new MdVoucher();
                mdVoucherDb.Title = mdVoucherVm.Title;
                mdVoucherDb.BotID = mdVoucherVm.BotID;
                mdVoucherDb.MessageStart = mdVoucherVm.MessageStart;
                mdVoucherDb.StartDate = mdVoucherVm.StartDate;
                mdVoucherDb.ExpirationDate = mdVoucherVm.ExpirationDate;
                mdVoucherDb.CardPayloadID = mdVoucherVm.CardPayloadID;
                mdVoucherDb.TitlePayload = mdVoucherVm.TitlePayload;
                mdVoucherDb.MessageError = "Số điện thoại không đúng, bạn vui lòng nhập lại.";
                mdVoucherDb.MessageEnd = mdVoucherVm.MessageEnd;
                mdVoucherDb.Code = mdVoucherVm.Code;
                mdVoucherDb.Payload = "";
                if (mdVoucherVm.CardPayloadID != null && mdVoucherVm.CardPayloadID != 0)
                {
                    mdVoucherDb.Payload = "postback_card_" + mdVoucherVm.CardPayloadID;
                }

                var files = System.Web.HttpContext.Current.Request.Files;
                if (files.Count != 0)
                {
                    var file = files[0];
                    Guid id = Guid.NewGuid();
                    string extentsion = new FileInfo(file.FileName).Extension.ToLower();
                    string fileName = id + "-" + new FileInfo(file.FileName).Name;

                    file.SaveAs(Path.Combine(HttpContext.Current.Server.MapPath("~/File/Images/")
                                             + "Voucher" + "/" + fileName));

                    mdVoucherDb.Image = "File/Images/Voucher/" + fileName;
                }

                _mdVoucherService.Create(mdVoucherDb);
                _mdVoucherService.Save();
                response = request.CreateResponse(HttpStatusCode.OK, mdVoucherDb);
                return response;
            }));
        }
示例#2
0
 public void Update(MdVoucher module)
 {
     _mdVoucherRepository.Update(module);
 }
示例#3
0
 public MdVoucher Create(MdVoucher module)
 {
     return(_mdVoucherRepository.Add(module));
 }