public JsonResult AddOne(int customerId, int customerTypeId)
        {
            var newCustomerToType = new CustomerToType()
            {
                CustomerId     = customerId,
                CustomerTypeId = customerTypeId
            };
            List <CustomerToType> test;

            test = db.CustomerToTypes.Where(c => c.CustomerId == customerId && c.CustomerTypeId == customerTypeId).ToList();
            if (test.Count < 1)
            {
                if (ModelState.IsValid)
                {
                    db.CustomerToTypes.Add(newCustomerToType);
                    db.SaveChanges();
                    return(Json(new { IsAdded = true, Content = "Kundetype er lagt til i databasen" }));
                }

                else
                {
                    return(Json(new { IsAdded = false, Content = "Modelstat er ikke valid" }));
                }
            }
            else
            {
                return(Json(new { IsAdded = false, Content = "Denne kundetypen er registrert fra før" }));
            }
        }
        public ActionResult DeleteConfirmed(int id)
        {
            CustomerToType customerToType = db.CustomerToTypes.Find(id);

            db.CustomerToTypes.Remove(customerToType);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Beispiel #3
0
        ///prøver igjen fra customerToType til dto

        public static CustomerToTypeDto MapOne(CustomerToType customerToType)
        {
            var temp = new CustomerToTypeDto()
            {
                CustomerTypeId = customerToType.CustomerTypeId,
                CustomerId     = customerToType.CustomerId
            };

            return(temp);
        }
Beispiel #4
0
        ///////CustomerToTypes
        public static CustomerToType Map_customerToTypeDto_ToType(CustomerToTypeDto customerToTypeDto)
        {
            var customerTotype = new CustomerToType()
            {
                CustomerId     = customerToTypeDto.CustomerId,
                CustomerTypeId = customerToTypeDto.CustomerTypeId
            };

            return(customerTotype);
        }
 public ActionResult Edit([Bind(Include = "Id,CustomerId,CustomerTypeId")] CustomerToType customerToType)
 {
     if (ModelState.IsValid)
     {
         db.Entry(customerToType).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CustomerId     = new SelectList(db.Customers, "Id", "FirmName", customerToType.CustomerId);
     ViewBag.CustomerTypeId = new SelectList(db.CustomerTypes, "Id", "CustomerTypeName", customerToType.CustomerTypeId);
     return(View(customerToType));
 }
        // GET: CustomerToTypes/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CustomerToType customerToType = db.CustomerToTypes.Find(id);

            if (customerToType == null)
            {
                return(HttpNotFound());
            }
            return(View(customerToType));
        }
Beispiel #7
0
        public IHttpActionResult CreateCustomerToTypes(CustomerToTypeDto dtoCustomerToType)
        {
            var customerToType = new CustomerToType();

            customerToType.CustomerId     = dtoCustomerToType.CustomerId;
            customerToType.CustomerTypeId = dtoCustomerToType.CustomerTypeId;
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            _context.CustomerToTypes.Add(customerToType);
            _context.SaveChanges();

            return
                (Ok("Created success")); // Created(new Uri(Request.RequestUri + "/" + customerToType.Id), dtoCustomerToType);
        }
        // GET: CustomerToTypes/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            CustomerToType customerToType = db.CustomerToTypes.Find(id);

            if (customerToType == null)
            {
                return(HttpNotFound());
            }
            ViewBag.CustomerId     = new SelectList(db.Customers, "Id", "FirmName", customerToType.CustomerId);
            ViewBag.CustomerTypeId = new SelectList(db.CustomerTypes, "Id", "CustomerTypeName", customerToType.CustomerTypeId);
            return(View(customerToType));
        }