public async Task <IActionResult> Create(ProductCreateViewModel user_data)
        {
            IFormFile image         = user_data.Image;
            var       imageErrorMsg = new StringBuilder();

            if (ModelState.IsValid &&
                image.Length > 0 &&
                (_fileHandler.CheckContentType(image, new List <string> {
                "image/jpg", "image/jpeg", "image/svg+xml", "image/png"
            }, imageErrorMsg) &
                 _fileHandler.CheckSize(image, 2 * StorageUnits.Megabyte, imageErrorMsg)))
            {
                string imagePath = _fileHandler.Upload(image);

                var product = new Product
                {
                    Name     = user_data.Name,
                    Price    = user_data.Price,
                    Quantity = user_data.Quantity,
                    Image    = imagePath
                };

                await _context.AddAsync(product);

                _context.SaveChanges();

                return(RedirectToRoute("product-index"));
            }

            ModelState.AddModelError("image", imageErrorMsg.ToString());

            return(View(user_data));
        }
Exemple #2
0
        public ActionResult Create(Product product)
        {
            foreach (var category in db.Categories)
            {
                product.CategoryList.Add(new SelectListItem {
                    Text = category.Name, Value = category.Id.ToString()
                });
            }

            if (product.CategoryId > 0)
            {
                product.AttributeList = BindAttributeList(product.CategoryId);
                if (product.AttributeId > 0)
                {
                    product.AttributeValuesList = BindAttributeValueList(product.AttributeId);
                }
            }

            if (ModelState.IsValid)
            {
                if (product.CategoryId > 0 && product.AttributeId > 0 && product.AttributeValuesId > 0)
                {
                    db.Products.Add(product);
                    db.SaveChanges();
                    return(RedirectToAction("Index"));
                }
            }


            return(View(product));
        }
Exemple #3
0
        public JsonResult AddPlayer(Player player)
        {
            _context.Players.Add(player);
            _context.SaveChanges();

            return(Json(new { status = "Player added successfully", player = player }));
        }
Exemple #4
0
        public IHttpActionResult PutEventMaster(int id, EventMaster eventMaster)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != eventMaster.EventId)
            {
                return(BadRequest());
            }

            db.Entry(eventMaster).State = EntityState.Modified;

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!EventMasterExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Exemple #5
0
        public void Insert()
        {
            Person person = new Person {
                Name = "test", Company = _db.Companies.First()
            };

            _db.Add(person);
            _db.SaveChanges();

            List <Person> personList = new List <Person>
            {
                new Person {
                    Name = "test1", Company = _db.Companies.First()
                },
                new Person {
                    Name = "test2", Company = _db.Companies.First()
                },
                new Person {
                    Name = "test3", Company = _db.Companies.First()
                }
            };

            _db.Persons.AddRange(personList);
            _db.SaveChanges();
        }
        public void CreateNews(News news, string userName)
        {
            var userId = _context.Users.Single(u => u.UserName == userName).Id;

            news.UserId        = userId;
            news.PublishedDate = DateTime.Today;

            _context.News.Add(news);
            _context.SaveChanges();
        }
        public void CreateComment(Comment comment, string userName)
        {
            var userId = _context.Users.Single(u => u.UserName == userName).Id;

            comment.UserId        = userId;
            comment.PublishedDate = DateTime.Today;

            _context.Comments.Add(comment);
            _context.SaveChanges();
        }
 public ActionResult Create(Employee employee)
 {
     if (ModelState.IsValid)
     {
         _context.Employees.Add(employee);
         _context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(employee));
 }
Exemple #9
0
 public ActionResult Create(Mascota mascota)
 {
     if (ModelState.IsValid)
     {
         _context.Mascotas.Add(mascota);
         _context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(mascota));
 }
        public void CreateRate(Rate rate, string userName)
        {
            var userId = _context.Users.Single(u => u.UserName == userName).Id;

            rate.UserId        = userId;
            rate.PublishedDate = DateTime.Today;

            _context.Rates.Add(rate);
            _context.SaveChanges();
        }
Exemple #11
0
 public IActionResult CreateDish(Dish newDish)
 {
     if (ModelState.IsValid)
     {
         dbContext.Dishes.Add(newDish);
         dbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View("CreateDish", newDish));
 }
Exemple #12
0
 public ActionResult Create(Category category)
 {
     if (ModelState.IsValid)
     {
         _context.Categories.Add(category);
         _context.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(category));
 }
Exemple #13
0
 public ActionResult Create(Person person)
 {
     if (ModelState.IsValid)
     {
         db.Person.Add(person);
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View());
 }
Exemple #14
0
        public IActionResult Edit(int?id, Adhoc ticket)
        {
            if (id == null)
            {
                return(NotFound());
            }


            string userId = null;

            // When user id is unavailable, display user as "Anomymous"
            if (User.Identity.Name == null || User.Identity.Name == "" || User.Identity.Name == "Anomymous user")
            {
                userId = "Anomymous";
            }
            else
            {
                userId = User.Identity.Name;
            }

            if (ModelState.IsValid)
            {
                // When status is changed by analyst to closed/cancelled, update analyst id (whoever closed the ticket)
                if (ticket.Status == "Closed" || ticket.Status == "Cancelled")
                {
                    Adhoc oticket = new Adhoc {
                        ID = ticket.ID, Status = ticket.Status, SupportAnalyst = userId, Details = ticket.Details, Type = ticket.Type
                    };
                    oticket.CompletedDate = System.DateTime.Now;
                    _contextAdhoc.Entry(oticket).Property("CompletedDate").IsModified  = true;
                    _contextAdhoc.Entry(oticket).Property("Status").IsModified         = true;
                    _contextAdhoc.Entry(oticket).Property("SupportAnalyst").IsModified = true;
                    _contextAdhoc.Entry(oticket).Property("Details").IsModified        = true;
                    _contextAdhoc.Entry(oticket).Property("Type").IsModified           = true;
                }
                else
                {
                    Adhoc oticket = new Adhoc {
                        ID = ticket.ID, Status = ticket.Status, SupportAnalyst = userId, Details = ticket.Details, Type = ticket.Type
                    };
                    _contextAdhoc.Entry(oticket).Property("Status").IsModified         = true;
                    _contextAdhoc.Entry(oticket).Property("SupportAnalyst").IsModified = true;
                    _contextAdhoc.Entry(oticket).Property("Details").IsModified        = true;
                    _contextAdhoc.Entry(oticket).Property("Type").IsModified           = true;
                }

                _contextAdhoc.SaveChanges();

                TempData["message"] = "Person edited!";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "There has been errors");
            return(View(ticket));
        }
        public ActionResult Create([Bind(Include = "Id,Name,PostalCode")] City city)
        {
            if (ModelState.IsValid)
            {
                db.Cities.Add(city);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(city));
        }
        public ActionResult Create([Bind(Include = "Id,FirstName,LastName,Address")] Person person)
        {
            if (ModelState.IsValid)
            {
                db.Persons.Add(person);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

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

            return(View(category));
        }
        public ActionResult Create([Bind(Include = "EmpleadoId,Nombre,Email,Telefono,Direccion")] Empleado empleado)
        {
            if (ModelState.IsValid)
            {
                db.Empleados.Add(empleado);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

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

            return(View(product));
        }
Exemple #20
0
        public ActionResult Create(AttributeValues attributeValues)
        {
            if (ModelState.IsValid)
            {
                db.AttributeValues.Add(attributeValues);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.AttributeId = new SelectList(db.Attributes, "Id", "Name", attributeValues.AttributeId);
            return(View(attributeValues));
        }
        public ActionResult Create([Bind(Include = "ID,Name,Brand,Weight,CurrentCategoryId")] Bike bike)
        {
            if (ModelState.IsValid)
            {
                db.Bikes.Add(bike);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.CurrentCategoryId = new SelectList(db.Categories, "ID", "Name", bike.CurrentCategoryId);
            return(View(bike));
        }
Exemple #22
0
 public ActionResult Create(Employee employee)
 {
     if (ModelState.IsValid)
     {
         _context.Employees.Add(employee);
         _context.SaveChanges();
         this.AddNotification("Employees Added Successfully", NotificationType.INFO);
         return(RedirectToAction("Index"));
     }
     this.AddNotification("Model State is invalid", NotificationType.ERROR);
     return(View(employee));
 }
 public IActionResult New(Dish thisDish)
 {
     if (ModelState.IsValid)
     {
         dbContext.Add(thisDish);
         dbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         return(View("New", thisDish));
     }
 }
Exemple #24
0
 public string Create(Employee employee)
 {
     try
     {
         context.Employees.Add(employee);
         context.SaveChanges();
         return("true");
     }
     catch (Exception ex)
     {
         return(ex.Message);
     }
 }
Exemple #25
0
 public IActionResult CreateDish(Crud AllDishes)
 {
     if (ModelState.IsValid)
     {
         dbContext.Add(AllDishes);
         dbContext.SaveChanges();
         return(RedirectToAction("Index"));
     }
     else
     {
         System.Console.WriteLine("error on adding dishes....this did not work");
         return(View("AddPage"));
     }
 }
 public ActionResult AddPerson(PersonModel personModel)
 {
     try
     {
         using (CrudContext db = new CrudContext())
         {
             var teacher = new Teacher()
             {
                 Address = new Address()
                 {
                     Street = personModel.Street,
                     City   = new City()
                     {
                         Id = personModel.CityId,
                         // CountryId = 1
                     }
                 },
                 Name  = personModel.Name,
                 Email = personModel.Email
             };
             db.Entry(teacher.Address.City).State = EntityState.Unchanged;
             db.Persons.Add(teacher);
             db.SaveChanges();
             return(Json(true, JsonRequestBehavior.AllowGet));
         }
     }
     catch (Exception ex)
     {
         return(Json(ex.Message, JsonRequestBehavior.AllowGet));
     }
 }
        public IActionResult Edit(int?id, Person person)
        {
            if (id == null)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                _context.Update(person);
                _context.SaveChanges();

                TempData["message"] = "Person edited!";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "There have been errors");
            return(View(person));
        }
Exemple #28
0
        public void NoTraking()
        {
            Contact contact = _db.Contacts.AsNoTracking().Single(c => c.Id == 1);

            Contact newContact = new Contact {
                Id = contact.Id, Email = contact.Email, Phone = contact.Phone
            };

            _db.Contacts.Add(newContact);
            _db.SaveChanges(); // It will not trhow an exception
        }
 public ActionResult Updateusers(UserModel user)
 {
     if (ModelState.IsValid)
     {
         CrudContext db = new CrudContext();
         db.Entry(user).State = EntityState.Modified;
         db.SaveChanges();
         ViewBag.Message = user.UserName + " successfully edited.";
         return(RedirectToAction("Retrive"));
     }
     return(View("Retrive"));
 }
        [ValidateAntiForgeryToken] // CSRF protection token
        public IActionResult Edit(int?id, Person person)
        {
            if (id == null)
            {
                return(NotFound());
            }
            _context.Update(person);
            _context.SaveChanges();

            TempData["Message"] = "Person edited!";
            return(RedirectToAction("Index"));
        }
Exemple #31
0
 private static void DeleteProjectCategory()
 {
     int Id;
     using (var context = new CrudContext())
     {
         var projectCategoies  = context.ProjectCategories.Where(c => c.Name == "Internal").ToList();
         foreach (var projectCategory in projectCategoies)
         {
             context.ProjectCategories.Remove(projectCategory);
         }
         context.SaveChanges();
     }
 }
Exemple #32
0
 private static void InsertProjectCategory()
 {
     var projectCategory = new ProjectCategory { Name = "Internal" };
     using (var context = new CrudContext())
     {
         context.ProjectCategories.Add(projectCategory);
         context.SaveChanges();
     }
     GetProjectCategory(projectCategory.Id);
 }
Exemple #33
0
        private static void UpdateProjectCategory()
        {
            int Id;
            using (var context = new CrudContext())
            {
                var projectCategory = context.ProjectCategories.FirstOrDefault(c => c.Name == "Internal");
                Id = projectCategory.Id;
                projectCategory.Description = "Internal projects";
                context.SaveChanges();

            }
            GetProjectCategory(Id);
        }
Exemple #34
0
        private static void InsertProjectCategory_Project()
        {
            try
            {
                var status = GetStatus();
                var projectCategory = new ProjectCategory
                {
                    Name = "Internal",

                };
                var project = new Project
                {
                    Name = "Jira1",
                    CompanyId = 1,
                    //ProjectId = Guid.NewGuid(),
                    //Works = {new Work(Guid.NewGuid()) {StatusId=status[0].StatusId,  TimeRange_Start=DateTime.Now.AddDays(-5),TimeRange_End=DateTime.Now.AddDays(-4) },
                    //    new Work(Guid.NewGuid()) {StatusId=status[0].StatusId, TimeRange_Start=DateTime.Now.AddDays(-3),TimeRange_End=DateTime.Now.AddDays(-2) }}
                };
                //project.ProjectCategory = projectCategory;
                projectCategory.Projects.Add(project);
                using (var context = new CrudContext())
                {
                    context.ProjectCategories.Add(projectCategory);
                    context.SaveChanges();
                }
            }
            catch (Exception e)
            {

                Console.WriteLine(e);
            }
        }