//[ValidateAntiForgeryToken]
        public ActionResult Create([Bind(Include = "DistributorAssign_Id,User_Id,Aktif,Distributor_Id,Urea,NPK,SP36,ZA,Organik")] DistributorAssigns distributorassign)
        {
            string dateToday       = DateTime.Now.ToString("M/dd/yyyy");
            string timeToday       = DateTime.Now.ToString("h:mm:ss tt");
            Claim  sessionUsername = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier);
            string userName        = sessionUsername.Value;

            if (ModelState.IsValid)
            {
                var dbdistributorassign = db.DistributorAssigns.Create();
                dbdistributorassign.DistributorAssign_Id = distributorassign.DistributorAssign_Id;
                dbdistributorassign.User_Id        = distributorassign.User_Id;
                dbdistributorassign.Distributor_Id = distributorassign.Distributor_Id;
                dbdistributorassign.Aktif          = distributorassign.Aktif;
                dbdistributorassign.Urea           = distributorassign.Urea;
                dbdistributorassign.NPK            = distributorassign.NPK;
                dbdistributorassign.SP36           = distributorassign.SP36;
                dbdistributorassign.ZA             = distributorassign.ZA;
                dbdistributorassign.Organik        = distributorassign.Organik;
                dbdistributorassign.Time_Edited    = timeToday;
                dbdistributorassign.Date_Edited    = dateToday;
                dbdistributorassign.Edited_by      = userName;
                db.DistributorAssigns.Add(dbdistributorassign);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.User_Id        = new SelectList(db.Users, "User_Id", "Name", distributorassign.User_Id);
            ViewBag.Distributor_Id = new SelectList(db.Distributors, "Distributor_Id", "Name", distributorassign.Distributor_Id);
            return(View(distributorassign));
        }
        //[ValidateAntiForgeryToken]
        public ActionResult DeleteConfirmed(int id)
        {
            DistributorAssigns distributorassign = db.DistributorAssigns.Find(id);

            db.DistributorAssigns.Remove(distributorassign);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        // GET: /DistributorAssigns/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DistributorAssigns distributorassign = db.DistributorAssigns.Find(id);

            if (distributorassign == null)
            {
                return(HttpNotFound());
            }
            return(View(distributorassign));
        }
        // GET: /DistributorAssigns/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            DistributorAssigns distributorassign = db.DistributorAssigns.Find(id);

            if (distributorassign == null)
            {
                return(HttpNotFound());
            }
            ViewBag.User_Id        = new SelectList(db.Users, "User_Id", "Name", distributorassign.User_Id);
            ViewBag.Distributor_Id = new SelectList(db.Distributors, "Distributor_Id", "Name", distributorassign.Distributor_Id);
            return(View(distributorassign));
        }
Exemple #5
0
 public ActionResult DistributorRelation(DistributorAssigns model)
 {
     if (ModelState.IsValid)
     {
         using (var db = new MainDbContext())
         {
             //var queryAssign = db.Assigns.Where(u => u.Id_user == model.Id_user && u.Kode_Pengecer == model.Kode_Pengecer).Select(u => u.Id_ass) ;
             var queryAssign = db.DistributorAssigns.FirstOrDefault(u => u.User_Id == model.User_Id && u.Distributor_Id == model.Distributor_Id);
             if (queryAssign == null)
             {
                 string timeToday = DateTime.Now.ToString("h:mm:ss tt");
                 string dateToday = DateTime.Now.ToString("M/dd/yyyy");
                 var    assign    = db.DistributorAssigns.Create();
                 assign.User_Id        = model.User_Id;
                 assign.Distributor_Id = model.Distributor_Id;
                 assign.Urea           = model.Urea;
                 assign.NPK            = model.NPK;
                 assign.SP36           = model.SP36;
                 assign.ZA             = model.ZA;
                 assign.Organik        = model.Organik;
                 assign.Time_Edited    = timeToday;
                 assign.Date_Edited    = dateToday;
                 db.DistributorAssigns.Add(assign);
                 db.SaveChanges();
             }
             else
             {
                 return(RedirectToAction("DistributorRelation"));
                 //return RedirectToAction("RegistrationPengecer");
             }
         }
     }
     else
     {
         ModelState.AddModelError("", "One or more fields have been");
     }
     return(View());
 }