Ejemplo n.º 1
0
        public IHttpActionResult PutFeedback(int id, Feedback feedback)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != feedback.FeedbackID)
            {
                return(BadRequest());
            }

            db.Entry(feedback).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FeedbackExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 2
0
        public IHttpActionResult PutEcard(int id, Ecard ecard)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != ecard.EcardID)
            {
                return(BadRequest());
            }

            db.Entry(ecard).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EcardExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 3
0
        public IHttpActionResult PutSubcriber(int id, Subcriber subcriber)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != subcriber.SubcriberID)
            {
                return(BadRequest());
            }

            db.Entry(subcriber).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SubcriberExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
        public IHttpActionResult PutOrderDetail(int id, OrderDetail OrderDetail)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != OrderDetail.OrderDetailID)
            {
                return(BadRequest());
            }

            db.Entry(OrderDetail).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!OrderDetailExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Ejemplo n.º 5
0
        public static int SendMailByOrderDetail(int?ItemID)
        {
            int id = 0;

            using (var context = new EgreetingContext())
            {
                var orderDetail = context.OrderDetails.Find(ItemID);
                id = orderDetail.OrderDetailID;

                MailMessage mail       = new MailMessage();
                SmtpClient  SmtpServer = new SmtpClient("smtp.gmail.com");

                Attachment data = new Attachment(HostingEnvironment.ApplicationPhysicalPath + "Uploads/EcardFiles/" + orderDetail.Ecard.EcardUrl);
                mail.Attachments.Add(data);


                mail.From = new MailAddress(WebConfigurationManager.AppSettings["EmailSender"]);
                mail.To.Add(orderDetail.Order.RecipientEmail);
                mail.Subject = orderDetail.Order.SendSubject + " - " + orderDetail.Order.SenderName;
                mail.Body    = orderDetail.Order.SendMessage;

                SmtpServer.Port        = 587;
                SmtpServer.Credentials = new System.Net.NetworkCredential(WebConfigurationManager.AppSettings["EmailSender"], WebConfigurationManager.AppSettings["PasswordEmail"]);
                SmtpServer.EnableSsl   = true;

                try
                {
                    SmtpServer.Send(mail);
                    orderDetail.SendStatus = true;
                    orderDetail.SendTime   = DateTime.Now;
                    context.OrderDetails.Attach(orderDetail);
                    context.Entry(orderDetail).State = EntityState.Modified;
                    context.SaveChanges();
                    var order = context.Set <Order>().Find(orderDetail.Order.OrderID);
                    if (!order.OrderDetails.Any(x => !x.SendStatus))
                    {
                        order.SendStatus = true;
                    }
                    context.Orders.Attach(order);
                    context.Entry(order).State = EntityState.Modified;
                    context.SaveChanges();
                }
                catch (Exception)
                {
                }
            }
            using (var db = new EgreetingContext())
            {
                var abc = db.OrderDetails.Find(id);
            }
            return(1);
        }
Ejemplo n.º 6
0
        public ActionResult Create([Bind(Include = "Subject,Message")] Feedback feedback, int?EcardID)
        {
            if (ModelState.IsValid)
            {
                using (var context = new EgreetingContext())
                {
                    var user           = new EgreetingUser();
                    var currentContext = System.Web.HttpContext.Current;
                    if (currentContext.User != null)
                    {
                        string email = currentContext.User.Identity.Name;
                        user = context.Set <EgreetingUser>().Where(x => x.Email.Equals(email)).FirstOrDefault();
                    }
                    if (user != null)
                    {
                        feedback.EgreetingUser = user;
                    }

                    var ecard = context.Set <Ecard>().Find(EcardID);
                    if (ecard != null)
                    {
                        feedback.Ecard = ecard;
                    }

                    feedback.CreatedDate = DateTime.Now;
                    context.Set <Feedback>().Add(feedback);
                    context.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }

            return(View(ViewNamesConstant.AdminFeedbacksCreate, feedback));
        }
Ejemplo n.º 7
0
        public ActionResult Create([Bind(Include = "SenderName,RecipientEmail,SendSubject,SendMessage")] Order order, string listEcardIDstring)
        {
            if (ModelState.IsValid)
            {
                using (var context = new EgreetingContext())
                {
                    var listEcardID      = listEcardIDstring.Split('-').Where(x => x.Length > 0).Select(x => Convert.ToInt32(x)).ToList();
                    var listOrderDetails = new List <OrderDetail>();
                    foreach (var ecardID in listEcardID)
                    {
                        var ecard        = context.Set <Ecard>().Find(ecardID);
                        var orderDetails = new OrderDetail
                        {
                            SendStatus  = false,
                            Ecard       = ecard,
                            CreatedDate = DateTime.Now,
                        };
                        listOrderDetails.Add(orderDetails);
                    }

                    order.OrderDetails = listOrderDetails;
                    order.SendStatus   = false;
                    order.TotalPrice   = listOrderDetails.Select(x => x.Ecard.Price).Sum();
                    order.CreatedDate  = DateTime.Now;
                    context.Set <Order>().Add(order);
                    context.SaveChanges();
                    return(Json(new { Code = "success", orderID = order.OrderID }));
                }
            }
            return(Json("fail"));
        }
Ejemplo n.º 8
0
        public ActionResult Edit([Bind(Include = "PaymentID,Month,Year,PaymentStatus")] Payment Payment, int?EgreetingUserID)
        {
            if (ModelState.IsValid)
            {
                using (var context = new EgreetingContext())
                {
                    var paymentUpdate = context.Set <Payment>().Find(Payment.PaymentID);
                    if (EgreetingUserID != null && paymentUpdate.EgreetingUser.EgreetingUserID != EgreetingUserID)
                    {
                        var egreetingUser = context.Set <EgreetingUser>().Find(EgreetingUserID);

                        if (egreetingUser != null)
                        {
                            paymentUpdate.EgreetingUser = egreetingUser;
                        }
                    }
                    paymentUpdate.Month         = Payment.Month;
                    paymentUpdate.Year          = Payment.Year;
                    paymentUpdate.PaymentStatus = Payment.PaymentStatus;
                    paymentUpdate.ModifiedDate  = DateTime.Now;
                    context.Set <Payment>().Attach(paymentUpdate);
                    context.Entry(paymentUpdate).State = EntityState.Modified;
                    context.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }
            ViewBag.EgreetingUsers = EgreetingUserBusiness.AllNoTracking.Where(x => x.Draft != true).Select(x => new { x.EgreetingUserID, x.Email }).ToDictionary(k => k.EgreetingUserID, v => v.Email);
            return(View(ViewNamesConstant.AdminPaymentsEdit, Payment));
        }
Ejemplo n.º 9
0
        public ActionResult Create([Bind(Include = "SenderName,RecipientEmail,SendSubject,SendMessage,ScheduleTime")] Order Order, string ListEcardString)
        {
            if (ModelState.IsValid)
            {
                using (var context = new EgreetingContext())
                {
                    var listEcardID      = ListEcardString.Split('-').Where(x => x.Length > 0).Select(x => Convert.ToInt32(x)).ToList();
                    var listOrderDetails = new List <OrderDetail>();
                    foreach (var ecardID in listEcardID)
                    {
                        var ecard        = context.Set <Ecard>().Find(ecardID);
                        var orderDetails = new OrderDetail
                        {
                            SendStatus  = false,
                            Ecard       = ecard,
                            CreatedDate = DateTime.Now,
                        };
                        listOrderDetails.Add(orderDetails);
                    }

                    Order.OrderDetails = listOrderDetails;
                    Order.SendStatus   = false;
                    Order.TotalPrice   = listOrderDetails.Select(x => x.Ecard.Price).Sum();
                    Order.CreatedDate  = DateTime.Now;
                    context.Set <Order>().Add(Order);
                    context.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }
            ViewBag.Ecards = EcardBusiness.AllNoTracking.Where(x => x.Draft != true).ToList();
            return(View(ViewNamesConstant.AdminOrdersCreate, Order));
        }
Ejemplo n.º 10
0
        public ActionResult CheckOut([Bind(Include = "SenderName,RecipientEmail,SendSubject,SendMessage")] Order order, string listEcardIDstring)
        {
            if (string.IsNullOrEmpty(order.RecipientEmail))
            {
                return(Json(new { Code = "fail", orderID = "" }));
            }
            if (ModelState.IsValid)
            {
                if (Request.IsAuthenticated)
                {
                    using (var context = new EgreetingContext())
                    {
                        string email        = User.Identity.Name;
                        var    userSend     = context.EgreetingUsers.Where(x => x.Email == email).FirstOrDefault();
                        bool   checkPayment = false;
                        if (userSend != null)
                        {
                            checkPayment = userSend.PaymentDueDate > DateTime.Now;
                        }

                        if (checkPayment)
                        {
                            var listEcardID      = listEcardIDstring.Split('-').Where(x => x.Length > 0).Select(x => Convert.ToInt32(x)).ToList();
                            var listOrderDetails = new List <OrderDetail>();
                            foreach (var ecardID in listEcardID)
                            {
                                var ecard        = context.Set <Ecard>().Find(ecardID);
                                var orderDetails = new OrderDetail
                                {
                                    SendStatus  = false,
                                    Ecard       = ecard,
                                    CreatedDate = DateTime.Now,
                                };
                                listOrderDetails.Add(orderDetails);
                            }

                            order.OrderDetails = listOrderDetails;
                            order.SendStatus   = false;
                            order.TotalPrice   = listOrderDetails.Select(x => x.Ecard.Price).Sum();
                            order.CreatedDate  = DateTime.Now;
                            context.Set <Order>().Add(order);
                            context.SaveChanges();
                            return(Json(new { Code = "success", orderID = order.OrderID }));
                        }
                        else
                        {
                            return(Json(new { Code = "subcriber", orderID = "" }));
                        }
                    }
                }
                else
                {
                    return(Json(new { Code = "forsending", orderID = "" }));
                }
            }
            return(Json(new { Code = "fail", orderID = "" }));
        }
Ejemplo n.º 11
0
 public void Save()
 {
     try
     {
         Context.SaveChanges();
     }
     catch (DbEntityValidationException e)
     {
         throw new Exception(e.Message);
     }
 }
Ejemplo n.º 12
0
        public ActionResult Edit([Bind(Include = "ScheduleSenderID,ScheduleTime,ScheduleType,SenderName,RecipientEmail,SendSubject,SendMessage")] ScheduleSender ScheduleSender, int?EcardID, int?EgreetingUserID)
        {
            if (ModelState.IsValid)
            {
                using (var context = new EgreetingContext())
                {
                    var scheduleSenderUpdate = context.Set <ScheduleSender>().Find(ScheduleSender.ScheduleSenderID);
                    // thinh: check user exist
                    if (EcardID != null)
                    {
                        var egreetingUser = context.Set <EgreetingUser>().Find(EgreetingUserID);
                        if (egreetingUser == null)
                        {
                            ModelState.AddModelError(string.Empty, "User not found!");
                            ViewBag.Ecards         = EcardBusiness.AllNoTracking.Where(x => x.Draft != true).Select(x => new { x.EcardID, x.EcardName }).ToDictionary(k => k.EcardID, v => v.EcardName);
                            ViewBag.EgreetingUsers = EgreetingUserBusiness.AllNoTracking.Where(x => x.Draft != true).Select(x => new { x.EgreetingUserID, x.Email }).ToDictionary(k => k.EgreetingUserID, v => v.Email);
                            return(View(ViewNamesConstant.AdminScheduleSendersCreate, ScheduleSender));
                        }
                        scheduleSenderUpdate.EgreetingUser = egreetingUser;
                    }

                    // thinh: check ecard exist
                    if (EcardID != null)
                    {
                        var ecard = context.Set <Ecard>().Find(EcardID);
                        if (ecard == null)
                        {
                            ModelState.AddModelError(string.Empty, "Ecard not found!");
                            ViewBag.Ecards         = EcardBusiness.AllNoTracking.Where(x => x.Draft != true).Select(x => new { x.EcardID, x.EcardName }).ToDictionary(k => k.EcardID, v => v.EcardName);
                            ViewBag.EgreetingUsers = EgreetingUserBusiness.AllNoTracking.Where(x => x.Draft != true).Select(x => new { x.EgreetingUserID, x.Email }).ToDictionary(k => k.EgreetingUserID, v => v.Email);
                            return(View(ViewNamesConstant.AdminScheduleSendersCreate, ScheduleSender));
                        }
                        scheduleSenderUpdate.Ecard = ecard;
                    }

                    // thinh: create schedule sender
                    scheduleSenderUpdate.ScheduleTime   = ScheduleSender.ScheduleTime;
                    scheduleSenderUpdate.ScheduleType   = ScheduleSender.ScheduleType;
                    scheduleSenderUpdate.SenderName     = ScheduleSender.SenderName;
                    scheduleSenderUpdate.RecipientEmail = ScheduleSender.RecipientEmail;
                    scheduleSenderUpdate.SendSubject    = ScheduleSender.SendSubject;
                    scheduleSenderUpdate.SendMessage    = ScheduleSender.SendMessage;
                    scheduleSenderUpdate.ModifiedDate   = DateTime.Now;

                    context.Set <ScheduleSender>().Attach(scheduleSenderUpdate);
                    context.Entry(scheduleSenderUpdate).State = EntityState.Modified;
                    context.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }
            ViewBag.Ecards         = EcardBusiness.AllNoTracking.Where(x => x.Draft != true).Select(x => new { x.EcardID, x.EcardName }).ToDictionary(k => k.EcardID, v => v.EcardName);
            ViewBag.EgreetingUsers = EgreetingUserBusiness.AllNoTracking.Where(x => x.Draft != true).Select(x => new { x.EgreetingUserID, x.Email }).ToDictionary(k => k.EgreetingUserID, v => v.Email);
            return(View(ViewNamesConstant.AdminScheduleSendersEdit, ScheduleSender));
        }
Ejemplo n.º 13
0
 public void Save()
 {
     try
     {
         Context.SaveChanges();
     }
     catch (DbUpdateException e)
     {
         throw new Exception(e.Message);
     }
 }
Ejemplo n.º 14
0
        public ActionResult Index()
        {
            using (var context = new EgreetingContext())
            {
                var currentDate              = DateTime.Now;
                var nextmonthDate            = DateTime.Now.AddMonths(1);
                var listUserID               = context.Set <Subcriber>().Where(x => x.Draft != true).Select(x => x.EgreetingUser.EgreetingUserID).ToList();
                var listUserPaymentThisMonth = context.Set <Payment>()
                                               .Where(x => x.Draft != true &&
                                                      x.Month == currentDate.Month &&
                                                      x.Year == currentDate.Year)
                                               .Select(x => x.EgreetingUser.EgreetingUserID).ToList();
                var listUserPaymentNextMonth = context.Set <Payment>()
                                               .Where(x => x.Draft != true &&
                                                      x.Month == nextmonthDate.Month &&
                                                      x.Year == nextmonthDate.Year)
                                               .Select(x => x.EgreetingUser.EgreetingUserID).ToList();
                var listUserIDThisMonth = listUserID.Where(x => !listUserPaymentThisMonth.Contains(x)).ToList();
                var listUserIDNextMonth = listUserID.Where(x => !listUserPaymentNextMonth.Contains(x)).ToList();

                var payments = new List <Payment>();
                foreach (var itemID in listUserIDThisMonth)
                {
                    var payment = new Payment
                    {
                        Month         = currentDate.Month,
                        Year          = currentDate.Year,
                        PaymentStatus = false,
                        EgreetingUser = context.Set <EgreetingUser>().Find(itemID),
                        CreatedDate   = DateTime.Now,
                    };
                    payments.Add(payment);
                }
                foreach (var itemID in listUserIDNextMonth)
                {
                    var payment = new Payment
                    {
                        Month         = nextmonthDate.Month,
                        Year          = nextmonthDate.Year,
                        PaymentStatus = false,
                        EgreetingUser = context.Set <EgreetingUser>().Find(itemID),
                        CreatedDate   = DateTime.Now,
                    };
                    payments.Add(payment);
                }
                context.Set <Payment>().AddRange(payments);
                context.SaveChanges();
            }
            return(RedirectToAction("Index", "Payments"));
        }
        public ActionResult Edit([Bind(Include = "EgreetingUserSlug,FirstName,LastName,Email,Password,ConfirmPassword,BirthDay,CreditCardNumber,CreditCardCVG,PaymentDueDate")] EgreetingUser egreetingUser, string UserId, string ListRole)
        {
            var file = Request.Files["Avatar"];

            byte[] image = new byte[file.ContentLength];
            file.InputStream.Read(image, 0, image.Length);

            if (ModelState.IsValid)
            {
                var user = UserManager.FindById(UserId);
                user.EgreetingUser.EgreetingUserSlug = egreetingUser.EgreetingUserSlug;
                user.EgreetingUser.FirstName         = egreetingUser.FirstName;
                user.EgreetingUser.LastName          = egreetingUser.LastName;
                user.EgreetingUser.BirthDay          = egreetingUser.BirthDay;
                user.EgreetingUser.CreditCardNumber  = egreetingUser.CreditCardNumber;
                user.EgreetingUser.CreditCardCVG     = egreetingUser.CreditCardCVG;
                user.EgreetingUser.PaymentDueDate    = egreetingUser.PaymentDueDate;
                if (file.ContentLength > 0)
                {
                    user.EgreetingUser.Avatar = image;
                }
                if (!string.IsNullOrEmpty(egreetingUser.Password))
                {
                    UserManager.RemovePassword(user.Id);
                    UserManager.AddPassword(user.Id, egreetingUser.Password);
                    UserManager.Update(user);
                }
                else
                {
                    UserManager.Update(user);
                }
                using (var context = new EgreetingContext())
                {
                    var lstRoleId = ListRole.Split('-').Where(x => x.Length > 0).Select(x => Convert.ToInt32(x)).ToList();
                    var eUser     = context.Set <EgreetingUser>().Where(x => x.Email.Equals(user.Email)).FirstOrDefault();
                    eUser.EgreetingRoles = context.Set <EgreetingRole>().Where(x => lstRoleId.Contains(x.EgreetingRoleID)).ToList();
                    context.Set <EgreetingUser>().Attach(eUser);
                    context.Entry(eUser).State = EntityState.Modified;
                    context.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }
            ViewBag.ListRole = EgreetingRoleBusiness.All.Where(x => x.Draft != true).ToList();
            return(View(ViewNamesConstant.AdminEgreetingUsersEdit, egreetingUser));
        }
Ejemplo n.º 16
0
        public async Task <ActionResult> Create([Bind(Include = "Email")] Subcriber subcriber)
        {
            if (ModelState.IsValid)
            {
                var egreetingUser = new EgreetingUser
                {
                    CreatedDate = DateTime.Now,
                    Avatar      = System.IO.File.ReadAllBytes(Server.MapPath("~/Content/Admin/dist/img/avatar.png")),
                    Email       = subcriber.Email,
                };
                var applicationUser = new ApplicationUser {
                    Email = egreetingUser.Email, UserName = egreetingUser.Email, EgreetingUser = egreetingUser
                };
                var result = await UserManager.CreateAsync(applicationUser, "delete123456Aa");

                using (var context = new EgreetingContext())
                {
                    var roleStore   = new RoleStore <IdentityRole>(context);
                    var roleManager = new RoleManager <IdentityRole>(roleStore);
                    var userStore   = new UserStore <ApplicationUser>(context);
                    var userManager = new UserManager <ApplicationUser>(userStore);
                    userManager.AddToRole(applicationUser.Id, "Subcriber");
                }
                if (result.Succeeded)
                {
                    using (var context = new EgreetingContext())
                    {
                        var eUser = context.Set <EgreetingUser>().Where(x => x.Email.Equals(egreetingUser.Email)).FirstOrDefault();
                        eUser.EgreetingRoles    = context.Set <EgreetingRole>().Where(x => x.EgreetingRoleName.Equals("Subcriber")).ToList();
                        subcriber.EgreetingUser = eUser;
                        context.Set <Subcriber>().Attach(subcriber);
                        context.Entry(subcriber).State = EntityState.Modified;
                        context.SaveChanges();
                    }
                    return(RedirectToAction("Index"));
                }
                AddErrors(result);
            }
            return(View(ViewNamesConstant.AdminSubcribersCreate, subcriber));
        }
        public ActionResult Create([Bind(Include = "EgreetingUserSlug,FirstName,LastName,Email,Password,ConfirmPassword,BirthDay,CreditCardNumber,CreditCardCVG,PaymentDueDate")] EgreetingUser egreetingUser, string ListRole)
        {
            var file = Request.Files["Avatar"];

            byte[] image = new byte[file.ContentLength];
            file.InputStream.Read(image, 0, image.Length);

            if (file.ContentLength == 0)
            {
                image = System.IO.File.ReadAllBytes(Server.MapPath("~/Content/Admin/dist/img/avatar.png"));
            }

            if (ModelState.IsValid)
            {
                egreetingUser.CreatedDate = DateTime.Now;
                egreetingUser.Avatar      = image;
                //egreetingUser.EgreetingRoles = lstEgreetingRole;
                var applicationUser = new ApplicationUser {
                    Email = egreetingUser.Email, UserName = egreetingUser.Email, EgreetingUser = egreetingUser
                };
                var result = UserManager.Create(applicationUser, egreetingUser.Password);
                if (result.Succeeded)
                {
                    using (var context = new EgreetingContext())
                    {
                        var lstRoleId = ListRole.Split('-').Where(x => x.Length > 0).Select(x => Convert.ToInt32(x)).ToList();
                        var eUser     = context.Set <EgreetingUser>().Where(x => x.Email.Equals(egreetingUser.Email)).FirstOrDefault();
                        eUser.EgreetingRoles = context.Set <EgreetingRole>().Where(x => lstRoleId.Contains(x.EgreetingRoleID)).ToList();
                        context.Set <EgreetingUser>().Attach(eUser);
                        context.Entry(eUser).State = EntityState.Modified;
                        context.SaveChanges();
                    }
                    return(RedirectToAction("Index"));
                }
                AddErrors(result);
            }
            ViewBag.ListRole = EgreetingRoleBusiness.All.Where(x => x.Draft != true).ToList();
            return(View(ViewNamesConstant.AdminEgreetingUsersCreate, egreetingUser));
        }
Ejemplo n.º 18
0
        public ActionResult Create([Bind(Include = "Month,Year,PaymentStatus")] Payment Payment, int?EgreetingUserID)
        {
            if (ModelState.IsValid)
            {
                using (var context = new EgreetingContext())
                {
                    var egreetingUser = context.Set <EgreetingUser>().Find(EgreetingUserID);
                    if (egreetingUser == null)
                    {
                        ViewBag.EgreetingUsers = EgreetingUserBusiness.AllNoTracking.Where(x => x.Draft != true).Select(x => new { x.EgreetingUserID, x.Email }).ToDictionary(k => k.EgreetingUserID, v => v.Email);
                        ModelState.AddModelError(string.Empty, "Need at least one email of user");
                        return(View(ViewNamesConstant.AdminPaymentsCreate, Payment));
                    }
                    Payment.EgreetingUser = egreetingUser;
                    Payment.CreatedDate   = DateTime.Now;
                    context.Set <Payment>().Add(Payment);
                    context.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }
            ViewBag.EgreetingUsers = EgreetingUserBusiness.AllNoTracking.Where(x => x.Draft != true).Select(x => new { x.EgreetingUserID, x.Email }).ToDictionary(k => k.EgreetingUserID, v => v.Email);
            return(View(ViewNamesConstant.AdminPaymentsCreate, Payment));
        }
Ejemplo n.º 19
0
        public ActionResult Edit([Bind(Include = "EcardID,EcardName,EcardSlug,EcardType,Price")] Ecard ecard)
        {
            if (ModelState.IsValid)
            {
                using (var context = new EgreetingContext())
                {
                    var ecardUpdate = context.Set <Ecard>().Find(ecard.EcardID);

                    var    thumbnailFile  = Request.Files["Thumbnail"];
                    var    ecardFile      = Request.Files["EcardFile"];
                    string pathThumbnail  = Server.MapPath("~/Uploads/Thumbnails/");
                    string pathEcardFiles = Server.MapPath("~/Uploads/EcardFiles/");
                    if (!Directory.Exists(pathEcardFiles))
                    {
                        Directory.CreateDirectory(pathEcardFiles);
                        if (!Directory.Exists(pathThumbnail))
                        {
                            Directory.CreateDirectory(pathThumbnail);
                        }
                    }

                    if (ecardFile != null)
                    {
                        if (!Path.GetExtension(ecardFile.FileName).CheckExtentionFile(ecard.EcardType))
                        {
                            ModelState.AddModelError(string.Empty, "File upload not support!");
                            ViewBag.Categories = CategoryBusiness.All.ToList();
                            return(View(ViewNamesConstant.AdminEcardsCreate, ecard));
                        }
                        ecard.EcardUrl = "EcardUrl_" + DateTime.Now.ToFileTime() + Path.GetExtension(ecardFile.FileName);
                        ecardFile.SaveAs(pathEcardFiles + ecard.EcardUrl);

                        if (thumbnailFile != null && Path.GetExtension(thumbnailFile.FileName).CheckExtentionFile())
                        {
                            ecard.ThumbnailUrl = "Thumbnail_" + DateTime.Now.ToFileTime() + Path.GetExtension(thumbnailFile.FileName);
                            thumbnailFile.SaveAs(pathThumbnail + ecard.ThumbnailUrl);
                        }
                        else
                        {
                            ecard.ThumbnailUrl = "thumbnail.png";
                        }
                    }

                    ecardUpdate.EcardName = ecard.EcardName;
                    if (!string.IsNullOrEmpty(ecard.EcardSlug))
                    {
                        if (!context.Set <Ecard>().Any(x => ecard.EcardSlug.Equals(x.EcardSlug)))
                        {
                            ecardUpdate.EcardSlug = ecard.EcardSlug;
                        }
                        else
                        {
                            ecardUpdate.EcardSlug = ecard.EcardSlug + DateTime.Now.ToFileTime();
                        }
                    }
                    ecardUpdate.EcardType    = ecard.EcardType;
                    ecardUpdate.Price        = ecard.Price;
                    ecardUpdate.ModifiedDate = DateTime.Now;

                    context.Set <Ecard>().Attach(ecardUpdate);
                    context.Entry(ecardUpdate).State = EntityState.Modified;
                    context.SaveChanges();
                }

                return(RedirectToAction("Index"));
            }
            ViewBag.Categories = CategoryBusiness.All.ToList();
            return(View(ViewNamesConstant.AdminEcardsEdit, ecard));
        }
Ejemplo n.º 20
0
        public void OnTimer(object sender, System.Timers.ElapsedEventArgs args)
        {
            eventLogServices.WriteEntry("Ghi log nghiệp vụ");
            // payment handle;
            using (var context = new EgreetingContext())
            {
                var currentDate              = DateTime.Now;
                var nextmonthDate            = DateTime.Now.AddMonths(1);
                var listUserID               = context.Set <Subcriber>().Where(x => x.Draft != true).Select(x => x.EgreetingUser.EgreetingUserID).ToList();
                var listUserPaymentThisMonth = context.Set <Payment>()
                                               .Where(x => x.Draft != true &&
                                                      x.Month == currentDate.Month &&
                                                      x.Year == currentDate.Year)
                                               .Select(x => x.EgreetingUser.EgreetingUserID).ToList();
                var listUserPaymentNextMonth = context.Set <Payment>()
                                               .Where(x => x.Draft != true &&
                                                      x.Month == nextmonthDate.Month &&
                                                      x.Year == nextmonthDate.Year)
                                               .Select(x => x.EgreetingUser.EgreetingUserID).ToList();
                var listUserIDThisMonth = listUserID.Where(x => !listUserPaymentThisMonth.Contains(x)).ToList();
                var listUserIDNextMonth = listUserID.Where(x => !listUserPaymentNextMonth.Contains(x)).ToList();

                var payments = new List <Payment>();
                foreach (var itemID in listUserIDThisMonth)
                {
                    var payment = new Payment
                    {
                        Month         = currentDate.Month,
                        Year          = currentDate.Year,
                        PaymentStatus = false,
                        EgreetingUser = context.Set <EgreetingUser>().Find(itemID),
                        CreatedDate   = DateTime.Now,
                    };
                    payments.Add(payment);
                }
                foreach (var itemID in listUserIDNextMonth)
                {
                    var payment = new Payment
                    {
                        Month         = nextmonthDate.Month,
                        Year          = nextmonthDate.Year,
                        PaymentStatus = false,
                        EgreetingUser = context.Set <EgreetingUser>().Find(itemID),
                        CreatedDate   = DateTime.Now,
                    };
                    payments.Add(payment);
                }
                context.Set <Payment>().AddRange(payments);
                context.SaveChanges();
            }

            // sendmail handle;
            using (var context = new EgreetingContext())
            {
                var listOrderUpdate = context.Orders.Where(x => x.Draft != true && x.SendStatus == false && x.ScheduleTime <= DateTime.Now).ToList();
                foreach (var item in listOrderUpdate)
                {
                    item.SendStatus   = true;
                    item.ModifiedDate = DateTime.Now;
                    foreach (var detail in item.OrderDetails)
                    {
                        detail.SendStatus   = true;
                        detail.SendTime     = DateTime.Now;
                        detail.ModifiedDate = DateTime.Now;
                    }
                    context.Orders.Attach(item);
                    context.Entry(item).State = System.Data.Entity.EntityState.Modified;
                    context.SaveChanges();
                }
            }
        }
Ejemplo n.º 21
0
        // GET: DummyData
        public ActionResult Index()
        {
            var faker = new Faker("en");

            using (var context = new EgreetingContext())
            {
                //20 category;
                var categories = new List <Category>();
                categories.Add(new Category {
                    CategoryID = 1, CategoryName = "Birthday", CategorySlug = "birthday"
                });
                categories.Add(new Category {
                    CategoryID = 2, CategoryName = "Wedding", CategorySlug = "wedding"
                });
                categories.Add(new Category {
                    CategoryID = 3, CategoryName = "New year", CategorySlug = "new-year"
                });
                categories.Add(new Category {
                    CategoryID = 4, CategoryName = "Festivals", CategorySlug = "festivals"
                });

                for (int i = 5; i < 20; i++)
                {
                    categories.Add(new Category
                    {
                        CategoryID   = i,
                        CategoryName = "Category " + i,
                        CategorySlug = "Category-" + i,
                        CreatedDate  = faker.Date.Past(),
                    });
                }
                context.Set <Category>().AddRange(categories);
                context.SaveChanges();
            }

            //3 role
            using (var context = new EgreetingContext())
            {
                var store   = new RoleStore <ApplicationRole>(context);
                var manager = new RoleManager <ApplicationRole>(store);
                var role    = new ApplicationRole
                {
                    Name          = "Admin",
                    EgreetingRole = new EgreetingRole
                    {
                        EgreetingRoleID   = 1,
                        EgreetingRoleName = "Admin",
                        CreatedDate       = faker.Date.Past(),
                    }
                };
                manager.Create(role);
                role = new ApplicationRole
                {
                    Name          = "User",
                    EgreetingRole = new EgreetingRole
                    {
                        EgreetingRoleID   = 2,
                        EgreetingRoleName = "User",
                        CreatedDate       = faker.Date.Past(),
                    }
                };
                manager.Create(role);
                role = new ApplicationRole
                {
                    Name          = "Subcriber",
                    EgreetingRole = new EgreetingRole
                    {
                        EgreetingRoleID   = 3,
                        EgreetingRoleName = "Subcriber",
                        CreatedDate       = faker.Date.Past(),
                    }
                };
                manager.Create(role);
            }

            //20 user
            using (var context = new EgreetingContext())
            {
                var image   = System.IO.File.ReadAllBytes(Server.MapPath("~/Content/Admin/dist/img/avatar.png"));
                var store   = new UserStore <ApplicationUser>(context);
                var manager = new UserManager <ApplicationUser>(store);

                var user = new ApplicationUser
                {
                    UserName      = "******",
                    Email         = "*****@*****.**",
                    EgreetingUser = new EgreetingUser
                    {
                        EgreetingUserID   = 1,
                        Email             = "*****@*****.**",
                        FirstName         = "Tien Thinh",
                        LastName          = "Nguyen",
                        Avatar            = image,
                        EgreetingUserSlug = generateSlug(),
                        BirthDay          = DateTime.Now,
                        PaymentDueDate    = DateTime.Now,
                        CreditCardNumber  = "123456789012",
                        CreditCardCVG     = "123",
                        CreatedDate       = faker.Date.Past(),
                    }
                };
                manager.Create(user, "123456aA@");
                manager.AddToRole(user.Id, "Admin");

                user = new ApplicationUser
                {
                    UserName      = "******",
                    Email         = "*****@*****.**",
                    EgreetingUser = new EgreetingUser
                    {
                        EgreetingUserID   = 2,
                        Email             = "*****@*****.**",
                        FirstName         = "Tien Thinh",
                        LastName          = "Nguyen",
                        Avatar            = image,
                        EgreetingUserSlug = generateSlug(),
                        BirthDay          = DateTime.Now,
                        PaymentDueDate    = DateTime.Now,
                        CreditCardNumber  = "123456789012",
                        CreditCardCVG     = "123",
                        CreatedDate       = faker.Date.Past(),
                    }
                };
                manager.Create(user, "123456aA@");
                manager.AddToRole(user.Id, "Admin");

                user = new ApplicationUser
                {
                    UserName      = "******",
                    Email         = "*****@*****.**",
                    EgreetingUser = new EgreetingUser
                    {
                        EgreetingUserID   = 3,
                        Email             = "*****@*****.**",
                        FirstName         = "Tien Thinh",
                        LastName          = "Nguyen",
                        Avatar            = image,
                        EgreetingUserSlug = generateSlug(),
                        BirthDay          = DateTime.Now,
                        PaymentDueDate    = DateTime.Now,
                        CreditCardNumber  = "123456789012",
                        CreditCardCVG     = "123",
                        CreatedDate       = faker.Date.Past(),
                    }
                };
                manager.Create(user, "123456aA@");
                manager.AddToRole(user.Id, "User");

                user = new ApplicationUser
                {
                    UserName      = "******",
                    Email         = "*****@*****.**",
                    EgreetingUser = new EgreetingUser
                    {
                        EgreetingUserID   = 4,
                        Email             = "*****@*****.**",
                        FirstName         = "Tien Thinh",
                        LastName          = "Nguyen",
                        Avatar            = image,
                        EgreetingUserSlug = generateSlug(),
                        BirthDay          = DateTime.Now,
                        PaymentDueDate    = DateTime.Now,
                        CreditCardNumber  = "123456789012",
                        CreditCardCVG     = "123",
                        CreatedDate       = faker.Date.Past(),
                    }
                };
                manager.Create(user, "123456aA@");
                manager.AddToRole(user.Id, "Subcriber");

                for (int i = 5; i <= 20; i++)
                {
                    user = new ApplicationUser
                    {
                        UserName      = "******" + i + "@gmail.com",
                        Email         = "subcriber" + i + "@gmail.com",
                        EgreetingUser = new EgreetingUser
                        {
                            EgreetingUserID   = 4,
                            Email             = "subcriber" + i + "@gmail.com",
                            FirstName         = "Tien Thinh " + i,
                            LastName          = "Nguyen",
                            Avatar            = image,
                            EgreetingUserSlug = generateSlug(),
                            BirthDay          = DateTime.Now,
                            PaymentDueDate    = DateTime.Now,
                            CreditCardNumber  = "123456789012",
                            CreditCardCVG     = "123",
                            CreatedDate       = faker.Date.Past(),
                        }
                    };
                    manager.Create(user, "123456aA@");
                    manager.AddToRole(user.Id, "Subcriber");
                }
            }


            // 100 Ecard
            using (var context = new EgreetingContext())
            {
                var ecards = new List <Ecard>();
                for (int i = 1; i <= 10; i++)
                {
                    var categoriesID = new List <int> {
                        faker.Random.Number(1, 20), faker.Random.Number(1, 20)
                    };
                    var ecard = new Ecard {
                        EcardID       = i,
                        EcardName     = faker.Commerce.ProductName(),
                        EcardSlug     = faker.Lorem.Slug() + i,
                        EcardType     = 4,
                        EcardUrl      = "Ecard_" + faker.Random.Number(1, 10) + ".mp4",
                        ThumbnailUrl  = "Thumbnail_" + faker.Random.Number(24, 39) + ".png",
                        Price         = faker.Random.Double() * 100,
                        Categories    = context.Set <Category>().Where(x => categoriesID.Contains(x.CategoryID)).ToList(),
                        EgreetingUser = context.Set <EgreetingUser>().Where(x => x.EgreetingUserID == 1).FirstOrDefault(),
                        CreatedDate   = faker.Date.Past(),
                    };
                    ecards.Add(ecard);
                }
                for (int i = 11; i <= 30; i++)
                {
                    var categoriesID = new List <int> {
                        faker.Random.Number(1, 20), faker.Random.Number(1, 20)
                    };
                    var ecard = new Ecard
                    {
                        EcardID       = i,
                        EcardName     = faker.Commerce.ProductName(),
                        EcardSlug     = faker.Lorem.Slug() + i,
                        EcardType     = 2,
                        EcardUrl      = "Ecard_" + faker.Random.Number(11, 23) + ".gif",
                        ThumbnailUrl  = "Thumbnail_" + faker.Random.Number(24, 39) + ".png",
                        Price         = faker.Random.Double() * 100,
                        Categories    = context.Set <Category>().Where(x => categoriesID.Contains(x.CategoryID)).ToList(),
                        EgreetingUser = context.Set <EgreetingUser>().Where(x => x.EgreetingUserID == 1).FirstOrDefault(),
                        CreatedDate   = faker.Date.Past(),
                    };
                    ecards.Add(ecard);
                }
                for (int i = 31; i <= 100; i++)
                {
                    var categoriesID = new List <int> {
                        faker.Random.Number(1, 20), faker.Random.Number(1, 20)
                    };
                    var ecard = new Ecard
                    {
                        EcardID       = i,
                        EcardName     = faker.Commerce.ProductName(),
                        EcardSlug     = faker.Lorem.Slug() + i,
                        EcardType     = 1,
                        EcardUrl      = "Ecard_" + faker.Random.Number(24, 39) + ".png",
                        ThumbnailUrl  = "Thumbnail_" + faker.Random.Number(24, 39) + ".png",
                        Price         = faker.Random.Double() * 100,
                        Categories    = context.Set <Category>().Where(x => categoriesID.Contains(x.CategoryID)).ToList(),
                        EgreetingUser = context.Set <EgreetingUser>().Where(x => x.EgreetingUserID == 1).FirstOrDefault(),
                        CreatedDate   = faker.Date.Past(),
                    };
                    ecards.Add(ecard);
                }
                context.Set <Ecard>().AddRange(ecards);
                context.SaveChanges();
            }

            // 500 Feedback
            using (var context = new EgreetingContext())
            {
                var feedbacks = new List <Feedback>();
                for (int i = 1; i <= 500; i++)
                {
                    var ecardID  = faker.Random.Number(1, 100);
                    var userID   = faker.Random.Number(1, 4);
                    var feedback = new Feedback
                    {
                        FeedbackID    = i,
                        Subject       = faker.Lorem.Sentence(10),
                        Message       = faker.Lorem.Sentences(4),
                        Ecard         = context.Set <Ecard>().Where(x => x.EcardID == ecardID).FirstOrDefault(),
                        EgreetingUser = context.Set <EgreetingUser>().Where(x => x.EgreetingUserID == userID).FirstOrDefault(),
                        CreatedDate   = faker.Date.Past(),
                    };
                    feedbacks.Add(feedback);
                }
                context.Set <Feedback>().AddRange(feedbacks);
                context.SaveChanges();
            }

            // 16 subcrieber
            using (var context = new EgreetingContext())
            {
                var subcribers = new List <Subcriber>();
                for (int i = 5; i <= 20; i++)
                {
                    var subcriber = new Subcriber
                    {
                        SubcriberID   = i,
                        Email         = "subcriber" + i + "@gmail.com",
                        EgreetingUser = context.Set <EgreetingUser>().Find(i),
                        CreatedDate   = faker.Date.Past(),
                    };
                    subcribers.Add(subcriber);
                }
                context.Set <Subcriber>().AddRange(subcribers);
                context.SaveChanges();
            }

            // 100 Payment
            using (var context = new EgreetingContext())
            {
                var payments = new List <Payment>();
                for (int i = 1; i <= 100; i++)
                {
                    var userID  = faker.Random.Number(5, 20);
                    var payment = new Payment
                    {
                        PaymentID     = i,
                        Month         = i % 12 == 0 ? 1 : i % 12,
                        Year          = faker.Random.Number(2000, 2019),
                        PaymentStatus = faker.Random.Bool(),
                        EgreetingUser = context.Set <EgreetingUser>().Find(userID),
                        CreatedDate   = faker.Date.Past(),
                    };
                    payments.Add(payment);
                }
                context.Set <Payment>().AddRange(payments);
                context.SaveChanges();
            }

            //200 Order
            using (var context = new EgreetingContext())
            {
                var orders = new List <Order>();
                for (int i = 1; i <= 200; i++)
                {
                    var ecardIDs = new List <int>()
                    {
                        faker.Random.Number(1, 100), faker.Random.Number(1, 100), faker.Random.Number(1, 100)
                    };
                    var orderDetails   = new List <OrderDetail>();
                    var sendStatusOder = true;
                    foreach (var item in ecardIDs)
                    {
                        bool sendStatus  = faker.Random.Bool();
                        var  orderDetail = new OrderDetail
                        {
                            SendStatus  = sendStatus,
                            Ecard       = context.Set <Ecard>().Find(item),
                            CreatedDate = faker.Date.Past(),
                        };
                        if (sendStatus)
                        {
                            orderDetail.SendTime = faker.Date.Soon();
                        }
                        orderDetails.Add(orderDetail);
                        sendStatusOder = sendStatusOder && sendStatus;
                    }
                    var userID = faker.Random.Number(5, 20);

                    var order = new Order
                    {
                        OrderID        = i,
                        SenderName     = faker.Lorem.Sentence(3),
                        RecipientEmail = "*****@*****.**",
                        SendSubject    = faker.Lorem.Sentence(4),
                        SendMessage    = faker.Lorem.Sentences(4),
                        ScheduleTime   = faker.Date.Past(),
                        SendStatus     = sendStatusOder,
                        TotalPrice     = faker.Random.Double(),
                        User           = context.Set <EgreetingUser>().Find(userID),
                        OrderDetails   = orderDetails,
                        CreatedDate    = faker.Date.Past(),
                    };
                    orders.Add(order);
                }
                context.Set <Order>().AddRange(orders);
                context.SaveChanges();
            }
            return(View());
        }
Ejemplo n.º 22
0
        public ActionResult Create([Bind(Include = "ScheduleTime,ScheduleType,SenderName,RecipientEmail,SendSubject,SendMessage")] ScheduleSender ScheduleSender, int?EcardID, int?EgreetingUserID)
        {
            if (ModelState.IsValid)
            {
                using (var context = new EgreetingContext())
                {
                    // thinh: check user exist
                    var egreetingUser = new EgreetingUser();
                    if (EcardID != null)
                    {
                        egreetingUser = context.Set <EgreetingUser>().Find(EgreetingUserID);
                        if (egreetingUser == null)
                        {
                            ModelState.AddModelError(string.Empty, "User not found!");
                            ViewBag.Ecards         = EcardBusiness.AllNoTracking.Where(x => x.Draft != true).Select(x => new { x.EcardID, x.EcardName }).ToDictionary(k => k.EcardID, v => v.EcardName);
                            ViewBag.EgreetingUsers = EgreetingUserBusiness.AllNoTracking.Where(x => x.Draft != true).Select(x => new { x.EgreetingUserID, x.Email }).ToDictionary(k => k.EgreetingUserID, v => v.Email);
                            return(View(ViewNamesConstant.AdminScheduleSendersCreate, ScheduleSender));
                        }
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "Need at least one user!");
                        ViewBag.Ecards         = EcardBusiness.AllNoTracking.Where(x => x.Draft != true).Select(x => new { x.EcardID, x.EcardName }).ToDictionary(k => k.EcardID, v => v.EcardName);
                        ViewBag.EgreetingUsers = EgreetingUserBusiness.AllNoTracking.Where(x => x.Draft != true).Select(x => new { x.EgreetingUserID, x.Email }).ToDictionary(k => k.EgreetingUserID, v => v.Email);
                        return(View(ViewNamesConstant.AdminScheduleSendersCreate, ScheduleSender));
                    }

                    // thinh: check ecard exist
                    var ecard = new Ecard();
                    if (EcardID != null)
                    {
                        ecard = context.Set <Ecard>().Find(EcardID);
                        if (ecard == null)
                        {
                            ModelState.AddModelError(string.Empty, "Ecard not found!");
                            ViewBag.Ecards         = EcardBusiness.AllNoTracking.Where(x => x.Draft != true).Select(x => new { x.EcardID, x.EcardName }).ToDictionary(k => k.EcardID, v => v.EcardName);
                            ViewBag.EgreetingUsers = EgreetingUserBusiness.AllNoTracking.Where(x => x.Draft != true).Select(x => new { x.EgreetingUserID, x.Email }).ToDictionary(k => k.EgreetingUserID, v => v.Email);
                            return(View(ViewNamesConstant.AdminScheduleSendersCreate, ScheduleSender));
                        }
                    }
                    else
                    {
                        ModelState.AddModelError(string.Empty, "Need at least one ecard!");
                        ViewBag.Ecards         = EcardBusiness.AllNoTracking.Where(x => x.Draft != true).Select(x => new { x.EcardID, x.EcardName }).ToDictionary(k => k.EcardID, v => v.EcardName);
                        ViewBag.EgreetingUsers = EgreetingUserBusiness.AllNoTracking.Where(x => x.Draft != true).Select(x => new { x.EgreetingUserID, x.Email }).ToDictionary(k => k.EgreetingUserID, v => v.Email);
                        return(View(ViewNamesConstant.AdminScheduleSendersCreate, ScheduleSender));
                    }

                    // thinh: create schedule sender
                    ScheduleSender.Ecard         = ecard;
                    ScheduleSender.EgreetingUser = egreetingUser;
                    ScheduleSender.CreatedDate   = DateTime.Now;

                    context.Set <ScheduleSender>().Add(ScheduleSender);
                    context.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }
            ViewBag.Ecards         = EcardBusiness.AllNoTracking.Where(x => x.Draft != true).Select(x => new { x.EcardID, x.EcardName }).ToDictionary(k => k.EcardID, v => v.EcardName);
            ViewBag.EgreetingUsers = EgreetingUserBusiness.AllNoTracking.Where(x => x.Draft != true).Select(x => new { x.EgreetingUserID, x.Email }).ToDictionary(k => k.EgreetingUserID, v => v.Email);
            return(View(ViewNamesConstant.AdminScheduleSendersCreate, ScheduleSender));
        }
Ejemplo n.º 23
0
        public ActionResult Create([Bind(Include = "EcardName,EcardSlug,EcardType,Price")] Ecard ecard, string ListCategoryString)
        {
            if (ModelState.IsValid)
            {
                var    thumbnailFile  = Request.Files["Thumbnail"];
                var    ecardFile      = Request.Files["EcardFile"];
                string pathThumbnail  = Server.MapPath("~/Uploads/Thumbnails/");
                string pathEcardFiles = Server.MapPath("~/Uploads/EcardFiles/");

                if (!Directory.Exists(pathEcardFiles))
                {
                    Directory.CreateDirectory(pathEcardFiles);
                    if (!Directory.Exists(pathThumbnail))
                    {
                        Directory.CreateDirectory(pathThumbnail);
                    }
                }


                if (ecardFile != null)
                {
                    if (!Path.GetExtension(ecardFile.FileName).CheckExtentionFile(ecard.EcardType))
                    {
                        ModelState.AddModelError(string.Empty, "File upload not support!");
                        ViewBag.Categories = CategoryBusiness.All.ToList();
                        return(View(ViewNamesConstant.AdminEcardsCreate, ecard));
                    }
                    ecard.EcardUrl = "EcardUrl_" + DateTime.Now.ToFileTime() + Path.GetExtension(ecardFile.FileName);
                    ecardFile.SaveAs(pathEcardFiles + ecard.EcardUrl);

                    if (thumbnailFile != null && Path.GetExtension(thumbnailFile.FileName).CheckExtentionFile())
                    {
                        ecard.ThumbnailUrl = "Thumbnail_" + DateTime.Now.ToFileTime() + Path.GetExtension(thumbnailFile.FileName);
                        thumbnailFile.SaveAs(pathThumbnail + ecard.ThumbnailUrl);
                    }
                    else
                    {
                        ecard.ThumbnailUrl = "thumbnail.png";
                    }
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "There is no is ecard file found!");
                    ViewBag.Categories = CategoryBusiness.All.ToList();
                    return(View(ViewNamesConstant.AdminEcardsCreate, ecard));
                }

                using (var context = new EgreetingContext())
                {
                    var lstCategoryID = ListCategoryString.Split('-').Where(x => x.Length > 0).Select(x => Convert.ToInt32(x)).ToList();
                    var lstCategory   = context.Set <Category>().Where(x => lstCategoryID.Contains(x.CategoryID)).ToList();
                    ecard.Categories = lstCategory;
                    if (context.Set <Ecard>().Any(x => ecard.EcardSlug.Equals(x.EcardSlug)))
                    {
                        ecard.EcardSlug = ecard.EcardSlug + DateTime.Now.ToFileTime();
                    }
                    var currentContext = System.Web.HttpContext.Current;
                    if (currentContext.User != null && Request.IsAuthenticated)
                    {
                        string email = "";
                        email = User.Identity.Name;
                        var user = context.Set <EgreetingUser>().Where(x => x.Email.Equals(email)).FirstOrDefault();
                        ecard.EgreetingUser = user;
                    }
                    ecard.CreatedDate = DateTime.Now;
                    context.Set <Ecard>().Add(ecard);
                    context.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }
            ViewBag.Categories = CategoryBusiness.All.ToList();
            return(View(ViewNamesConstant.AdminEcardsCreate, ecard));
        }
Ejemplo n.º 24
0
        public ActionResult Edit([Bind(Include = "OrderID,SenderName,RecipientEmail,SendSubject,SendStatus,SendMessage,ScheduleTime")] Order Order, string ListEcardString)
        {
            if (string.IsNullOrEmpty(Order.RecipientEmail))
            {
                ModelState.AddModelError("RecipientEmail", "Recipient's email can't not be empty!");
            }
            if (ModelState.IsValid)
            {
                using (var context = new EgreetingContext())
                {
                    var orderUpdate = context.Set <Order>().Find(Order.OrderID);


                    if (orderUpdate == null)
                    {
                        ViewBag.Ecards = EcardBusiness.AllNoTracking.Where(x => x.Draft != true).ToList();
                        ModelState.AddModelError(string.Empty, "Order not found!");
                        return(View(ViewNamesConstant.AdminOrdersEdit, Order));
                    }

                    // thinh: check sending status
                    if (orderUpdate.SendStatus == true || orderUpdate.OrderDetails.Any(x => x.Draft != true && x.SendStatus))
                    {
                        ViewBag.Ecards = EcardBusiness.AllNoTracking.Where(x => x.Draft != true).ToList();
                        ModelState.AddModelError(string.Empty, "Can't edit because ecard had been sended!");
                        return(View(ViewNamesConstant.AdminOrdersEdit, Order));
                    }

                    // thinh: remove order detail
                    foreach (var orderDetailRemove in orderUpdate.OrderDetails)
                    {
                        orderDetailRemove.Draft = true;
                    }

                    // thinh: update order detail
                    var listEcardID      = ListEcardString.Split('-').Where(x => x.Length > 0).Select(x => Convert.ToInt32(x)).ToList();
                    var listOrderDetails = new List <OrderDetail>();
                    foreach (var ecardID in listEcardID)
                    {
                        var ecard        = context.Set <Ecard>().Find(ecardID);
                        var orderDetails = new OrderDetail
                        {
                            SendStatus  = Order.SendStatus,
                            Ecard       = ecard,
                            CreatedDate = DateTime.Now,
                        };
                        listOrderDetails.Add(orderDetails);
                    }
                    orderUpdate.OrderDetails = listOrderDetails;

                    // thinh: update order
                    orderUpdate.SendSubject    = Order.SendSubject;
                    orderUpdate.SendStatus     = Order.SendStatus;
                    orderUpdate.SenderName     = Order.SenderName;
                    orderUpdate.RecipientEmail = Order.RecipientEmail;
                    orderUpdate.SendMessage    = Order.SendMessage;
                    orderUpdate.ScheduleTime   = Order.ScheduleTime;
                    orderUpdate.ModifiedDate   = DateTime.Now;

                    context.Set <Order>().Attach(orderUpdate);
                    context.Entry(orderUpdate).State = EntityState.Modified;
                    context.SaveChanges();
                }
                return(RedirectToAction("Index"));
            }
            ViewBag.Ecards = EcardBusiness.AllNoTracking.Where(x => x.Draft != true).ToList();
            return(View(ViewNamesConstant.AdminOrdersEdit, Order));
        }