public ActionResult Create([Bind(Include = "Id,City,Street,ZipCode")] Adress adress)
        {
            if (ModelState.IsValid)
            {
                db.Adress.Add(adress);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(adress));
        }
        public ActionResult Create([Bind(Include = "Id,Name")] AppType appType)
        {
            if (ModelState.IsValid)
            {
                db.AppType.Add(appType);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(appType));
        }
        public ActionResult Create([Bind(Include = "Id,Name")] Category category)
        {
            if (ModelState.IsValid)
            {
                db.Category.Add(category);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(category));
        }
Exemple #4
0
        public ActionResult Create([Bind(Include = "Id,Name")] Realization realization)
        {
            if (ModelState.IsValid)
            {
                db.Realization.Add(realization);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(realization));
        }
Exemple #5
0
        public ActionResult Create([Bind(Include = "Id,Name,AccountNumber")] BankAccount bankAccount)
        {
            if (ModelState.IsValid)
            {
                db.BankAccount.Add(bankAccount);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(bankAccount));
        }
        public ActionResult Create([Bind(Include = "Id,Name,Category_Id")] Product product)
        {
            if (ModelState.IsValid)
            {
                db.Product.Add(product);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Category_Id = new SelectList(db.Category, "Id", "Name", product.Category_Id);
            return(View(product));
        }
Exemple #7
0
        public ActionResult Create([Bind(Include = "Id,FirstName,LastName,Phone,Email,Password,Role_Id,Adress_Id,BankAccount_Id")] User user)
        {
            if (ModelState.IsValid)
            {
                RMASystem.User.SetFirstLetterOfNameToUpper(user);
                db.User.Add(user);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.Adress_Id      = new SelectList(db.Adress, "Id", "City", user.Adress_Id);
            ViewBag.BankAccount_Id = new SelectList(db.BankAccount, "Id", "Name", user.BankAccount_Id);
            ViewBag.Role_Id        = new SelectList(db.Role, "Id", "Name", user.Role_Id);
            return(View(user));
        }
Exemple #8
0
 public void SaveToDb()
 {
     using (var context = new RmaEntities()) {
         context.Email.Add(_emailMessage);
         context.SaveChanges();
     }
 }
 int CreateAddress(Adress address)
 {
     using (var context = new RmaEntities()) {
         var addedAddress = context.Adress.Add(address);
         context.SaveChanges();
         return(addedAddress.Id);
     }
 }
 int CreateBankAccount(BankAccount bankAccount)
 {
     using (var context = new RmaEntities()) {
         var addedBankAccount = context.BankAccount.Add(bankAccount);
         context.SaveChanges();
         return(addedBankAccount.Id);
     }
 }
        public async Task <ActionResult> Create(
            [Bind(Include = "Id,Name,InvoiceNo,Purschace,Content,Description,Expectations,Cost,Start,Pending,InProgress,End,Product_Id,AppType_Id,Realization_Id,Statue_Id,Result_Id,Client_Id,Employee_Id")] Application application)
        {
            if (ModelState.IsValid)
            {
                db.Application.Add(application);
                CreateCode(application);
                if (HttpContext.User.IsInRole("Klient"))
                {
                    SetClient(application);
                }
                SetStatus(application);
                SetStatusDate(application);
                db.SaveChanges();

                var mailMessage = PrepareNewMessage(application);
                var mailEntity  = new Email {
                    Sender         = mailMessage.From.ToString(),
                    Reciper        = mailMessage.To.ToString(),
                    Subject        = mailMessage.Subject,
                    Content        = mailMessage.Body,
                    Application_Id = application.Id,
                    PostDate       = DateTime.Now
                };
                await SendMessage(mailMessage);

                SaveMessage(mailEntity);

                return(HttpContext.User.IsInRole("Klient")
                                                        ? RedirectToAction("UserApplication")
                                                        : RedirectToAction("Index"));
            }

            ViewBag.AppType_Id     = new SelectList(db.AppType, "Id", "Name", application.AppType_Id);
            ViewBag.Client_Id      = new SelectList(db.User, "Id", "Identificator", application.Client_Id);
            ViewBag.Employee_Id    = new SelectList(db.User, "Id", "Identificator", application.Employee_Id);
            ViewBag.Product_Id     = new SelectList(db.Product, "Id", "Name", application.Product_Id);
            ViewBag.Realization_Id = new SelectList(db.Realization, "Id", "Name", application.Realization_Id);
            ViewBag.Result_Id      = new SelectList(db.Result, "Id", "Name", application.Result_Id);
            ViewBag.Statue_Id      = new SelectList(db.Statue, "Id", "Name", application.Statue_Id);
            return(View(application));
        }
 int AddNewBank(RegisterUserViewModel model)
 {
     using (var context = new RmaEntities()) {
         var newBank = new BankAccount {
             Name          = model.BankName,
             AccountNumber = model.AccountNumber
         };
         context.BankAccount.Add(newBank);
         context.SaveChanges();
         return(newBank.Id);
     }
 }
 int AddNewAddress(RegisterUserViewModel model)
 {
     using (var context = new RmaEntities()) {
         var newAddress = new Adress {
             City    = model.City,
             Street  = model.Street,
             ZipCode = model.ZipCode
         };
         context.Adress.Add(newAddress);
         context.SaveChanges();
         return(newAddress.Id);
     }
 }
        public ActionResult ConfirmEmail(string token, string email)
        {
            using (var context = new RmaEntities()) {
                var userId = int.Parse(HashHelper.Decrypt(token, email));
                var user   = context.User.FirstOrDefault(u => u.Id == userId && u.Email == email);
                if (user == null)
                {
                    return(null);
                }

                user.EmailConfirmed = true;
                context.Entry(user).Property(p => p.EmailConfirmed).IsModified = true;
                context.SaveChanges();
                return(RedirectToAction("Index"));
            }
        }
        bool ChangeValues(User user, Adress address, BankAccount bankAccount)
        {
            using (var context = new RmaEntities()) {
                var oldUser = context.User.Find(user.Id);
                if (oldUser != null)
                {
                    if (context.User.Any(m => m.Email == user.Email && m.Id != user.Id))
                    {
                        ModelState.AddModelError("", "Podany e-mail już istnieje!");
                        return(false);
                    }
                    ChangeValues(user, address, bankAccount, oldUser);
                }

                context.SaveChanges();
                return(true);
            }
        }
 void AddNewUser(RegisterUserViewModel model, int addressId, int bankId)
 {
     using (var context = new RmaEntities()) {
         var newUser = new User {
             FirstName      = model.FirstName,
             LastName       = model.LastName,
             Email          = model.Email,
             Password       = model.Password,
             Phone          = model.Phone,
             Adress_Id      = addressId,
             BankAccount_Id = bankId,
             Role_Id        = context.Role.First(r => r.Name == "Klient").Id
         };
         context.User.Add(newUser);
         context.SaveChanges();
         model.Id = newUser.Id;
     }
 }