Beispiel #1
0
        public ActionResult Edit(BDSTransaction model)
        {
            if (!ModelState.IsValid)
            {
                LoadDataList();
                ViewBag.Success = false;
                ViewBag.Message = Resource.SaveFailed;
                return(View(model));
            }
            var modelDB = _service.GetItem(model.ID);

            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.UpdateItem(model);


            var account = _serviceAccount.GetItem(model.IdAccount);

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

            if (model.RefTranHis.HasValue)
            {
                var tranhis = _serviceTranHis.GetIQueryableItems().Where(T => T.ID == model.RefTranHis).FirstOrDefault();
                tranhis.Name         = model.Name;
                tranhis.Description  = model.Name;
                tranhis.KeySearch    = model.Name.NormalizeD();
                tranhis.Active       = 1;
                tranhis.ModifiedUser = 1;
                tranhis.ModifiedDate = DateTime.Now;
                tranhis.TypeTran     = 1;
                tranhis.PointTran    = model.Point;
                tranhis.MoneyTran    = (model.Money + model.MoneyEventAdd);
                _serviceTranHis.UpdateItem(tranhis);
            }
            ViewBag.Success = true;
            ViewBag.Message = Resource.SaveSuccessful;
            return(Edit(model.ID));
        }
Beispiel #2
0
        public ActionResult Review(BDSNew model, HttpPostedFileBase[] files, int[] img_id)
        {
            if (!ModelState.IsValid)
            {
                LoadDataList();
                ViewBag.Success = false;
                ViewBag.Message = Resource.SaveFailed;
                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.BDSAccount     = _serviceAccount.GetItem(model.IdAcount);
            model.FromDeadline   = DateTime.Now;
            model.ShowEmail      = model.ShowEmail;
            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();

            if (model.Status == 1)
            {
                model.DateReup  = model.FromCreateNews >= DateTime.Now ? model.FromCreateNews : DateTime.Now;
                model.MaxReup   = 3;
                model.CountReup = 0;
                if (model.RefTranHis.HasValue)
                {
                    var tranHis = _serviceTransactionHistory.GetItem(model.RefTranHis.Value);
                    tranHis.Active = 1;
                    _serviceTransactionHistory.UpdateItem(tranHis);
                }
                var totalDay = model.ToCreateNews.Value.Subtract(model.FromCreateNews.Value).TotalDays;
                if (totalDay < 1)
                {
                    totalDay = 1;
                }
                else
                {
                    totalDay = Math.Ceiling(totalDay);
                }
                var listDate = _serviceNewsDate.GetIQueryableItems().Where(T => T.IdNews == model.ID && T.Active == 1).ToList();
                foreach (var item in listDate)
                {
                    item.Active = 0;
                    _serviceNewsDate.UpdateItem(item);
                }
                if (model.IdTypeNews == 1)
                {
                    BDSNewsDate d1 = new BDSNewsDate
                    {
                        Name           = "TBT=" + totalDay,
                        KeySearch      = "",
                        IdTypeNews     = model.IdTypeNews,
                        IdNews         = model.ID,
                        CreateUser     = 1,
                        CreateDate     = DateTime.Now,
                        Description    = "",
                        DIndex         = 1,
                        FromCreateNews = model.FromCreateNews,
                        ToCreateNews   = model.ToCreateNews,
                        Status         = 1
                    };
                    _serviceNewsDate.CreateItem(d1);

                    BDSNewsDate d2 = new BDSNewsDate
                    {
                        Name           = "TFE=" + 90,
                        KeySearch      = "",
                        IdTypeNews     = 4,
                        IdNews         = model.ID,
                        CreateUser     = 1,
                        DIndex         = 2,
                        CreateDate     = DateTime.Now,
                        Description    = "",
                        FromCreateNews = model.ToCreateNews.Value.AddDays(1),
                        ToCreateNews   = model.ToCreateNews.Value.AddDays(90),
                        Status         = 1
                    };
                    _serviceNewsDate.CreateItem(d2);
                    model.IdNewsDates = d1.ID;
                }
                if (model.IdTypeNews == 2)
                {
                    BDSNewsDate d1 = new BDSNewsDate
                    {
                        Name           = "TVP=" + totalDay,
                        KeySearch      = "",
                        IdTypeNews     = model.IdTypeNews,
                        IdNews         = model.ID,
                        CreateUser     = 1,
                        DIndex         = 1,
                        CreateDate     = DateTime.Now,
                        Description    = "",
                        FromCreateNews = model.FromCreateNews,
                        ToCreateNews   = model.ToCreateNews,
                        Status         = 1
                    };
                    _serviceNewsDate.CreateItem(d1);

                    BDSNewsDate d2 = new BDSNewsDate
                    {
                        Name           = "TBT=" + 60,
                        KeySearch      = "",
                        IdTypeNews     = 1,
                        DIndex         = 2,
                        IdNews         = model.ID,
                        CreateUser     = 1,
                        CreateDate     = DateTime.Now,
                        Description    = "",
                        FromCreateNews = model.ToCreateNews.Value.AddDays(1),
                        ToCreateNews   = model.ToCreateNews.Value.AddDays(60),
                        Status         = 1
                    };
                    _serviceNewsDate.CreateItem(d2);

                    BDSNewsDate d3 = new BDSNewsDate
                    {
                        Name           = "TFE=" + 90,
                        KeySearch      = "",
                        IdTypeNews     = 4,
                        IdNews         = model.ID,
                        CreateUser     = 1,
                        DIndex         = 3,
                        CreateDate     = DateTime.Now,
                        Description    = "",
                        FromCreateNews = model.ToCreateNews.Value.AddDays(61),
                        ToCreateNews   = model.ToCreateNews.Value.AddDays(150),
                        Status         = 1
                    };
                    _serviceNewsDate.CreateItem(d3);
                    model.IdNewsDates = d1.ID;
                }
                if (model.IdTypeNews == 3)
                {
                    BDSNewsDate d1 = new BDSNewsDate
                    {
                        Name           = "TDB=" + totalDay,
                        KeySearch      = "",
                        DIndex         = 1,
                        IdTypeNews     = model.IdTypeNews,
                        IdNews         = model.ID,
                        CreateUser     = 1,
                        CreateDate     = DateTime.Now,
                        Description    = "",
                        FromCreateNews = model.FromCreateNews,
                        ToCreateNews   = model.ToCreateNews,
                        Status         = 1
                    };
                    _serviceNewsDate.CreateItem(d1);

                    BDSNewsDate d2 = new BDSNewsDate
                    {
                        Name           = "TBT=" + 60,
                        KeySearch      = "",
                        IdTypeNews     = 1,
                        DIndex         = 2,
                        IdNews         = model.ID,
                        CreateUser     = 1,
                        CreateDate     = DateTime.Now,
                        Description    = "",
                        FromCreateNews = model.ToCreateNews.Value.AddDays(1),
                        ToCreateNews   = model.ToCreateNews.Value.AddDays(60),
                        Status         = 1
                    };
                    _serviceNewsDate.CreateItem(d2);

                    BDSNewsDate d3 = new BDSNewsDate
                    {
                        Name           = "TFE=" + 90,
                        KeySearch      = "",
                        IdTypeNews     = 4,
                        DIndex         = 3,
                        IdNews         = model.ID,
                        CreateUser     = 1,
                        CreateDate     = DateTime.Now,
                        Description    = "",
                        FromCreateNews = model.ToCreateNews.Value.AddDays(61),
                        ToCreateNews   = model.ToCreateNews.Value.AddDays(150),
                        Status         = 1
                    };
                    _serviceNewsDate.CreateItem(d3);
                    model.IdNewsDates = d1.ID;
                }
                if (model.IdTypeNews == 4)
                {
                    BDSNewsDate d1 = new BDSNewsDate
                    {
                        Name           = "TFE=" + totalDay,
                        KeySearch      = "",
                        DIndex         = 1,
                        IdTypeNews     = model.IdTypeNews,
                        IdNews         = model.ID,
                        CreateUser     = 1,
                        CreateDate     = DateTime.Now,
                        Description    = "",
                        FromCreateNews = model.FromCreateNews,
                        ToCreateNews   = model.ToCreateNews,
                        Status         = 1
                    };
                    _serviceNewsDate.CreateItem(d1);
                    model.IdNewsDates = d1.ID;
                }
            }

            _service.UpdateItem(model);

            if (model.RefTranHis.HasValue)
            {
                var    type  = _serviceNewsType.GetItem(model.IdTypeNewsCuurent);
                String Fname = "Edit 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"));
                var    tran  = _serviceTransactionHistory.GetItem(model.RefTranHis.Value);
                tran.Name += "-" + Fname;
                var difMoney = model.TotalMoney - tran.MoneyTran;
                if (difMoney != 0)
                {
                    tran.MoneyTran += difMoney;
                    tran.Active     = 1;
                    _serviceTransactionHistory.UpdateItem(tran);
                    model.BDSAccount.Money += difMoney;
                    _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 (img_id != null && img_id.Length > 0)
            {
                var listPic = _servicePicture.GetIQueryableItems().Where(T => T.advert_id == model.ID && !img_id.Contains(T.ID)).ToList();
                foreach (var pic in listPic)
                {
                    _servicePicture.DeleteItem(pic.ID);
                }
            }

            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
                        });
                    }
                }
            }



            ViewBag.Success = true;
            ViewBag.Message = Resource.SaveSuccessful;
            return(Redirect("/"));;
        }