示例#1
0
        public ActionResult Edit(ViewModels.CompanyEditViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }
            using (var entities = new SPOInvoiceEntities())
            {
                var model = entities.Company.FirstOrDefault(c => c.id == viewModel.id);

                model.InvoiceAddress = viewModel.InvoiceAddress;
                model.InvoiceDefaultPaymentTermsDays = viewModel.InvoiceDefaultPaymentTermsDays;
                model.InvoiceEmail       = viewModel.InvoiceEmail;
                model.InvoiceName        = viewModel.InvoiceName;
                model.InvoicePostAddress = viewModel.InvoicePostAddress;
                model.InvoicePostNo      = viewModel.InvoicePostNo;
                model.name    = viewModel.name;
                model.OrgNo   = viewModel.OrgNo;
                model.Founded = viewModel.Founded;

                var changeLog = new Models.ChangeLog();
                changeLog.datum       = DateTime.Now;
                changeLog.description = "Company with id " + viewModel.id + " was edited";
                entities.ChangeLog.Add(changeLog);

                entities.SaveChanges();
                return(RedirectToAction("Index"));
            }
        }
示例#2
0
 public ActionResult Delete(int id)
 {
     using (var entities = new SPOInvoiceEntities())
     {
         var obj = entities.Company.FirstOrDefault(x => x.id == id);
         entities.Company.RemoveRange(new[] { obj });
         entities.SaveChanges();
         return(RedirectToAction("Index"));
     }
 }
示例#3
0
        public ActionResult Create(ViewModels.CompanyEditViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }
            using (var entities = new SPOInvoiceEntities())
            {
                var model = new Models.Company();
                model.InvoiceAddress = viewModel.InvoiceAddress;
                model.InvoiceDefaultPaymentTermsDays = viewModel.InvoiceDefaultPaymentTermsDays;
                model.InvoiceEmail       = viewModel.InvoiceEmail;
                model.InvoiceName        = viewModel.InvoiceName;
                model.InvoicePostAddress = viewModel.InvoicePostAddress;
                model.InvoicePostNo      = viewModel.InvoicePostNo;
                model.name    = viewModel.name;
                model.OrgNo   = viewModel.OrgNo;
                model.Founded = viewModel.Founded;

                entities.Company.Add(model);

                // EF FIXAR RELATIONER!!!
                //GENOM PROPERTY
                //var invoice = new Models.Invoice();
                //invoice.Datum = DateTime.Now;
                //invoice.InvoiceAddress = model.InvoiceAddress;
                //invoice.Company = model;
                //entities.Invoice.Add(invoice);



                var changeLog = new Models.ChangeLog();
                changeLog.datum       = DateTime.Now;
                changeLog.description = "A new Company  was created";
                entities.ChangeLog.Add(changeLog);

                entities.SaveChanges();



                return(RedirectToAction("Index"));
            }
        }