Пример #1
0
        public ActionResult AddItemToCurrentBook(string siteID, string sitePriceID, string siteItemID, string price, string durasi, string totalprice, string startDate, string endDate, string prevSite)
        {
            AddBookOutputModel OutPutData = new AddBookOutputModel();

            if (HttpContext.Session.GetString(SessionKeyID) != null && HttpContext.Session.GetString(SessionKeyID) != "")
            {
                AddItemToCurrentBookListInputModel bookData = new AddItemToCurrentBookListInputModel();
                bookData.BookID = Guid.Parse(HttpContext.Session.GetString(SessionKeyBookID));
                bookData.BookDetailIDForDeleted = Guid.Parse(prevSite);
                bookData.Data = new List <AddItemToCurrentBookInputModel>();

                AddItemToCurrentBookInputModel Data = new AddItemToCurrentBookInputModel();
                Data.SitePriceID  = Guid.Parse(sitePriceID);
                Data.SiteID       = Guid.Parse(siteID);
                Data.SiteItemID   = Guid.Parse(siteItemID);
                Data.UserID       = Guid.Parse(HttpContext.Session.GetString(SessionKeyID));
                Data.StartDate    = DateTime.Parse(startDate);
                Data.EndDate      = DateTime.Parse(endDate);
                Data.Qty          = int.Parse(durasi);
                Data.Price        = double.Parse(price);
                Data.TotalPerItem = double.Parse(totalprice);
                bookData.Data.Add(Data);

                JsonConvert.SerializeObject(bookData);
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(BaseAPI + "Site/");
                    //HTTP POST
                    var postTask = client.PostAsJsonAsync <AddItemToCurrentBookListInputModel>("AddItemToCurrentBook", bookData);
                    postTask.Wait();

                    var result = postTask.Result;
                    if (result.IsSuccessStatusCode)
                    {
                        return(RedirectToAction("Index", "Booking"));
                    }
                    else
                    {
                        TempData["CustomError"] = "Fail to add data. Please contact administrator.";
                    }
                }
                return(Json(OutPutData));
            }
            else
            {
                TempData["CustomError"] = "Mohon masuk sebelum mengakses halaman ini.";
                return(RedirectToAction("Index", "Home"));
            }
        }
Пример #2
0
        public ActionResult <AddItemToCurrentBookResponseModel> AddItemToCurrentBook([FromBody] AddItemToCurrentBookListInputModel data)
        {
            AddItemToCurrentBookResponseModel res = new AddItemToCurrentBookResponseModel();

            try
            {
                BookBL bl   = new BookBL(DbContext);
                var    temp = bl.ChangeItemCurrentBook(data);

                string configJSON = JsonConvert.SerializeObject(AppSettings.EmailConfig);

                //start send Email to Admin
                var         bodyAdmin = bl.BuilBookChangeReceiptToAdmin(data);
                MailMessage message   = new MailMessage();
                message.To.Add("*****@*****.**");
                message.Body       = bodyAdmin;
                message.Subject    = "Booking ";
                message.From       = new MailAddress(AppSettings.EmailConfig.FromAddress);
                message.IsBodyHtml = true;
                PdfConvertEngine pdfEngine = new PdfConvertEngine();
                var        pdfPath         = pdfEngine.ConvertHTMLToPDF(bodyAdmin, AppSettings.PDFPath, temp.BookNo.Replace('/', '_'));
                Attachment dataPDF         = new Attachment(pdfPath);
                message.Attachments.Add(dataPDF);
                EmailSenderEngine emailEngine = new EmailSenderEngine();
                emailEngine.SendEmail(message, configJSON);
                dataPDF.Dispose();
                //End send Email to admin

                //start send Email to Media buyer
                var            bodyBuyer      = bl.BuilBookChangeReceiptToMediaBuyer(data);
                UserRepository userRepo       = new UserRepository(DbContext);
                var            mediaBuyerInfo = userRepo.FindByID(data.Data[0].UserID).FirstOrDefault();
                message = new MailMessage();
                message.To.Add(mediaBuyerInfo.UserName);
                message.Body       = bodyBuyer;
                message.Subject    = "Booking ";
                message.From       = new MailAddress(AppSettings.EmailConfig.FromAddress);
                message.IsBodyHtml = true;
                pdfEngine          = new PdfConvertEngine();
                pdfPath            = pdfEngine.ConvertHTMLToPDF(bodyBuyer, AppSettings.PDFPath, temp.BookNo.Replace('/', '_'));
                dataPDF            = new Attachment(pdfPath);
                message.Attachments.Add(dataPDF);
                emailEngine = new EmailSenderEngine();
                emailEngine.SendEmail(message, configJSON);
                dataPDF.Dispose();
                //End send Email to Media buyer


                res.data     = temp;
                res.Message  = "Success";
                res.Response = true;

                return(Ok(res));
            }
            catch (Exception ex)
            {
                res.Message  = ex.Message;
                res.Response = false;

                return(BadRequest(res));
            }
        }
Пример #3
0
        public ActionResult AddItemToCurrentBook(string siteID, string sitePriceID, string siteItemID, string price, string durasi, string totalprice, string startDate, string endDate, string prevSite)
        {
            AddBookOutputModel OutPutData = new AddBookOutputModel();

            if (HttpContext.Session.GetString(SessionKeyID) != null && HttpContext.Session.GetString(SessionKeyID) != "")
            {
                AddItemToCurrentBookListInputModel bookData = new AddItemToCurrentBookListInputModel();
                bookData.BookID = Guid.Parse(HttpContext.Session.GetString(SessionKeyBookID));
                bookData.BookDetailIDForDeleted = Guid.Parse(prevSite);
                bookData.Data = new List <AddItemToCurrentBookInputModel>();

                AddItemToCurrentBookInputModel Data = new AddItemToCurrentBookInputModel();
                Data.SitePriceID  = Guid.Parse(sitePriceID);
                Data.SiteID       = Guid.Parse(siteID);
                Data.SiteItemID   = Guid.Parse(siteItemID);
                Data.UserID       = Guid.Parse(HttpContext.Session.GetString(SessionKeyID));
                Data.StartDate    = DateTime.Parse(startDate);
                Data.EndDate      = DateTime.Parse(endDate);
                Data.Qty          = int.Parse(durasi);
                Data.Price        = double.Parse(price);
                Data.TotalPerItem = double.Parse(totalprice);
                bookData.Data.Add(Data);

                JsonConvert.SerializeObject(bookData);
                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(BaseAPI + "Site/");
                    //HTTP POST
                    var postTask = client.PostAsJsonAsync <AddItemToCurrentBookListInputModel>("AddItemToCurrentBook", bookData);
                    postTask.Wait();

                    var result = postTask.Result;
                    if (result.IsSuccessStatusCode)
                    {
                        return(RedirectToAction("Index", "Booking"));
                    }
                    else
                    {
                        TempData["CustomError"] = "Gagal menambah data. Mohon hubungi admin.";
                    }
                }
                return(Json(OutPutData));
            }
            else
            {
                TempData["CustomError"] = "Silakan masuk sebelum menggunakan situs web.";
                //if (HttpContext.Session.GetString(Loginfrom) == "ADM/SPV")
                //{
                //	return RedirectToAction("AdminLogon", "Login");
                //}
                //else if (HttpContext.Session.GetString(Loginfrom) == "MDO")
                //{
                //	return RedirectToAction("OwnerLogon", "Login");
                //}
                //else
                //{
                //	return RedirectToAction("OwnerLogon", "Login");
                //}
                return(RedirectToAction("Logon", "Login"));
            }
        }