public long AddNew(HolderSvcModel model) { using (MyDbContext dbc = new MyDbContext()) { CommonService <SettingsEntity> scs = new CommonService <SettingsEntity>(dbc); CommonService <StockItemEntity> cs = new CommonService <StockItemEntity>(dbc); CommonService <JournalTypeEntity> jcs = new CommonService <JournalTypeEntity>(dbc); CommonService <HolderEntity> hcs = new CommonService <HolderEntity>(dbc); if (hcs.GetAll().SingleOrDefault(h => h.Mobile == model.Mobile) != null) { return(-2); } StockItemEntity stockItem = cs.GetAll().Where(s => s.Id == model.StockItemId).SingleOrDefault(); long holderadd = jcs.GetAll().SingleOrDefault(j => j.Name == "holderadd").Id; if (stockItem == null) { return(-1); } var seting = scs.GetAll().SingleOrDefault(s => s.Name == "takecashtime"); HolderEntity entity = new HolderEntity(); entity.Amount = model.Amount; entity.BankAccount = model.BankAccount; entity.BankName = model.BankName; entity.Contact = model.Mobile; entity.IdNumber = model.IdNumber; entity.Mobile = model.Mobile; entity.Name = model.Name; entity.Gender = model.Gender; entity.Proportion = model.Amount / stockItem.TotalAmount; entity.TotalAssets = model.Amount; entity.Password = model.Password; entity.Copies = model.Copies; entity.TakeCashTime = entity.CreateTime.AddDays(Convert.ToDouble(seting.Value)); stockItem.HaveCopies = stockItem.HaveCopies - model.Copies; JournalEntity journal = new JournalEntity(); journal.BalanceAmount = entity.TotalAssets; journal.InAmount = entity.Amount; journal.JournalTypeId = holderadd; journal.Remark = "后台添加股东"; dbc.Holder.Add(entity); dbc.Journal.Add(journal); dbc.SaveChanges(); return(entity.Id); } }
public ActionResult Add(HolderAddModel model) { if (string.IsNullOrEmpty(model.Name)) { return(Json(new AjaxResult { Status = "0", Msg = "股东名不能为空" })); } if (string.IsNullOrEmpty(model.Mobile)) { return(Json(new AjaxResult { Status = "0", Msg = "股东手机号不能为空" })); } long num; if (!long.TryParse(model.Mobile, out num)) { return(Json(new AjaxResult { Status = "0", Msg = "股东手机号必须是数字" })); } if (model.Mobile.Length != 11) { return(Json(new AjaxResult { Status = "0", Msg = "股东手机号必须是11位" })); } if (string.IsNullOrEmpty(model.IdNumber)) { return(Json(new AjaxResult { Status = "0", Msg = "股东身份证号不能为空" })); } if (string.IsNullOrEmpty(model.Password)) { return(Json(new AjaxResult { Status = "0", Msg = "密码不能为空" })); } if (model.Amount <= 0) { return(Json(new AjaxResult { Status = "0", Msg = "认购金额不能为空" })); } if (model.Copies != Convert.ToInt64(Session["Copies"])) { return(Json(new AjaxResult { Status = "0", Msg = "认购金额与份数不符" })); } long haveCopies = stockService.GetByKeyName(KeyName).HaveCopies; if (model.Copies > haveCopies) { return(Json(new AjaxResult { Status = "0", Msg = "认购份数不能大于可认购份数" })); } HolderSvcModel holder = new HolderSvcModel(); holder.Amount = model.Amount; holder.Gender = model.Gender; holder.IdNumber = model.IdNumber; holder.Mobile = model.Mobile; holder.Name = model.Name; holder.Password = model.Password; holder.StockItemId = stockService.GetIdByKeyName(KeyName); holder.Copies = model.Copies; long id = holderService.AddNew(holder); if (id <= 0) { if (id == -2) { return(Json(new AjaxResult { Status = "0", Msg = "手机号码已经存在" })); } return(Json(new AjaxResult { Status = "0", Msg = "添加股东失败" })); } return(Json(new AjaxResult { Status = "1", Data = "/admin/holder/list" })); }
public bool Update(HolderSvcModel model) { using (MyDbContext dbc = new MyDbContext()) { CommonService <HolderEntity> cs = new CommonService <HolderEntity>(dbc); CommonService <StockItemEntity> scs = new CommonService <StockItemEntity>(dbc); var holder = cs.GetAll().SingleOrDefault(h => h.Id == model.Id); var stockItem = scs.GetAll().SingleOrDefault(s => s.Id == model.StockItemId); if (holder == null) { return(false); } if (stockItem == null) { return(false); } JournalEntity journal = new JournalEntity(); if (model.Flag) { holder.Amount = holder.Amount + model.Amount; holder.BankAccount = model.BankAccount; holder.BankName = model.BankName; holder.Contact = model.Contact; holder.IdNumber = model.IdNumber; holder.Mobile = model.Mobile; holder.Name = model.Name; holder.Password = model.Password; holder.Proportion = holder.Amount / stockItem.TotalAmount; holder.TotalAssets = holder.Amount + holder.TotalBonus - holder.HaveBonus; holder.TakeBonus = holder.TotalBonus - holder.HaveBonus; journal.BalanceAmount = holder.TotalAssets; journal.InAmount = model.Amount; journal.JournalTypeId = 1; journal.Remark = "后台编辑添加股东股份"; } else { holder.Amount = holder.Amount - model.Amount; holder.BankAccount = model.BankAccount; holder.BankName = model.BankName; holder.Contact = model.Contact; holder.IdNumber = model.IdNumber; holder.Mobile = model.Mobile; holder.Name = model.Name; holder.Password = model.Password; holder.Proportion = holder.Amount / stockItem.TotalAmount; holder.TotalAssets = holder.Amount + holder.TotalBonus - holder.HaveBonus; holder.TakeBonus = holder.TotalBonus - holder.HaveBonus; journal.BalanceAmount = holder.TotalAssets; journal.InAmount = model.Amount; journal.JournalTypeId = 1; journal.Remark = "后台编辑减少股东股份"; } dbc.Journal.Add(journal); dbc.SaveChanges(); return(true); } }