예제 #1
0
        public ActionResult Create(BDSTransaction model)
        {
            if (!ModelState.IsValid)
            {
                LoadDataList();
                return(View(model));
            }
            model.TranDate   = DateTime.Now;
            model.BDSAccount = _serviceAccount.GetItem(model.IdAccount);
            if (model.IdBank.HasValue)
            {
                model.BDSBank = _serviceBank.GetItem(model.IdBank.Value);
            }
            if (model.IdBranch.HasValue)
            {
                model.BDSBranch = _serviceBranch.GetItem(model.IdBranch.Value);
            }

            model.KeySearch = model.Name.NormalizeD() + " " + model.TranDate.ToString("dd/MM/yyyy HH:mm:ss").NormalizeD() + " " +
                              (String.IsNullOrEmpty(model.Description)
                                  ? ""
                                  : model.Description.NormalizeD());
            _service.CreateItem(model);
            var account = _serviceAccount.GetItem(model.IdAccount);

            account.Money += model.Money + model.MoneyEventAdd;
            account.Point += model.Point;
            _serviceAccount.UpdateItem(account);


            BDSTransactionHistory tran = new BDSTransactionHistory
            {
                Name        = model.Name,
                Description = model.Name,
                KeySearch   = model.Name.NormalizeD(),
                Active      = 1,
                CreateUser  = 1,
                CreateDate  = DateTime.Now,
                TypeTran    = 1,
                PointTran   = model.Point,
                MoneyTran   = (model.Money + model.MoneyEventAdd),
                DateTran    = DateTime.Now,
                Status      = 1
            };

            _serviceTranHis.CreateItem(tran);
            model.RefTranHis = tran.ID;
            _service.UpdateItem(model);


            return(RedirectToAction("Index"));
        }
예제 #2
0
        public ActionResult Create(BDSNew model, HttpPostedFileBase[] files)
        {
            if (!ModelState.IsValid)
            {
                LoadDataList();
                model.BDSPictures = _servicePicture.GetIQueryableItems().Where(T => T.Active == 1 && T.advert_id == model.ID).ToList();
                var list = (List <SelectListItem>)ViewBag.Careers;
                List <SelectListItem> lst = new List <SelectListItem>();
                foreach (var item in list)
                {
                    if (model.Career.Split(',').Contains(item.Value))
                    {
                        lst.Add(new SelectListItem {
                            Value = item.Value, Text = item.Text, Selected = true
                        });
                    }
                }


                ViewBag.MultiSelectCareer = lst;
                return(View(model));
            }
            var fromDate = model.FromDateToDateString.Split('-')[0];
            var toDate   = model.FromDateToDateString.Split('-')[1];

            model.FromCreateNews    = DateTime.Parse(fromDate.Trim(), MvcApplication.CultureInfo, DateTimeStyles.None);
            model.ToCreateNews      = DateTime.Parse(toDate.Trim(), MvcApplication.CultureInfo, DateTimeStyles.None);
            model.FromDeadline      = DateTime.Now;
            model.IdTypeNewsCuurent = model.IdTypeNews;
            model.ShowEmail         = model.ShowEmail;
            model.BDSAccount        = _serviceAccount.GetItem(model.IdAcount);
            model.KeySearch         = model.Title.NormalizeD() + " " + model.BDSAccount.Email + " " + _serviceNewsType.GetItem(model.IdTypeNews).Name.NormalizeD() + " " + _serviceEmployerInformation.GetIQueryableItems().Where(T => T.IdAccount == model.IdAcount).FirstOrDefault().Name + " " + model.DesCompany.NormalizeD();
            _service.UpdateItem(model);



            var type = _serviceNewsType.GetItem(model.IdTypeNewsCuurent);



            String Fname = "Đăng tin '{A}' trong vòng '{B}' ngày tổng giá phải trả '{C}' VNĐ";
            string name  = Fname.Replace("{A}", type.Name).Replace("{B}", ((int)Math.Ceiling(model.ToCreateNews.Value.Subtract(model.FromCreateNews.Value).TotalDays)) + "").Replace("{C}", model.TotalMoney.ToString("n2"));

            Davisoft_BDSProject.Domain.Entities.BDSTransactionHistory tran = new Davisoft_BDSProject.Domain.Entities.BDSTransactionHistory()
            {
                Name        = name,
                Description = name,
                KeySearch   = name.NormalizeD(),
                Active      = 1,
                CreateUser  = 1,
                CreateDate  = DateTime.Now,
                TypeTran    = 2,
                PointTran   = 0,
                MoneyTran   = model.TotalMoney,
                DateTran    = DateTime.Now,
                Status      = 0
            };
            _serviceTransactionHistory.CreateItem(tran);
            model.RefTranHis = tran.ID;
            _service.UpdateItem(model);
            model.BDSAccount.Money -= model.TotalMoney;
            _serviceAccount.UpdateItem(model.BDSAccount);
            var listMap = db.BDSNews_Career.Where(T => T.ID_News == model.ID).ToList();

            foreach (var item in listMap)
            {
                db.Entry(item).State = EntityState.Deleted;
            }
            db.SaveChanges();
            foreach (var item in model.Career.Split(','))
            {
                BDSNews_Career i = new BDSNews_Career {
                    ID_News = model.ID, ID_Career = int.Parse(item)
                };
                db.Entry(i).State = EntityState.Added;
            }
            db.SaveChanges();

            if (files != null && files.Length > 0)
            {
                for (int i = 0; i < files.Length; i++)
                {
                    if (files[i] != null)
                    {
                        byte[] binaryData;
                        binaryData = new Byte[files[i].InputStream.Length];
                        long bytesRead = files[i].InputStream.Read(binaryData, 0, (int)files[i].InputStream.Length);
                        files[i].InputStream.Close();
                        string base64String = System.Convert.ToBase64String(binaryData, 0, binaryData.Length);
                        SaveImg(new NewsPictures {
                            nameImg = files[i].FileName, idProducts = model.ID, isactive = 1, index = i, cfile = base64String
                        });
                    }
                }
            }
            db.SaveChanges();



            return(RedirectToAction("Index"));
        }