public void UpdateMaterialPreparation(decimal value, int materialPreparationProcessID, int componentID)
        {
            //ComponentMaterialPreparationProcess currentCMPP = db.ComponentMaterialPreparationProcesses.Where(x => x.MaterialPreparationProcessID == materialPreparationProcessID).SingleOrDefault();

            //if (value > currentCMPP.Value)
            //{
            //    ComponentMaterialPreparationProcess newCMPP = db.ComponentMaterialPreparationProcesses.Find(currentCMPP.ID);
            //    newCMPP.Value = value;
            //    newCMPP.LastModified = DateTime.Now;
            //    newCMPP.LastModifiedBy = User.Identity.Name;
            //    db.SaveChanges();
            //}

            ComponentMaterialPreparationProcess currentCMPP = db.ComponentMaterialPreparationProcesses.Where(x => x.MaterialPreparationProcessID == materialPreparationProcessID && x.ComponentID == componentID).SingleOrDefault();

            if (currentCMPP != null && value > currentCMPP.Value)
            {
                currentCMPP.Value          = value;
                currentCMPP.LastModified   = DateTime.Now;
                currentCMPP.LastModifiedBy = User.Identity.Name;
                db.SaveChanges();
            }
            else if (currentCMPP == null)
            {
                ComponentMaterialPreparationProcess newCMPP = new ComponentMaterialPreparationProcess();
                newCMPP.ComponentID = componentID;
                newCMPP.MaterialPreparationProcessID = materialPreparationProcessID;
                newCMPP.Value          = value;
                newCMPP.LastModified   = newCMPP.Created = DateTime.Now;
                newCMPP.LastModifiedBy = newCMPP.CreatedBy = User.Identity.Name;
                db.ComponentMaterialPreparationProcesses.Add(newCMPP);
                db.SaveChanges();
            }
        }
예제 #2
0
        /// <summary>
        /// MethodEditMaterialPreparation befungsi untuk mengubah sebuah data di material preparation
        /// </summary>
        /// <param name="componentMaterialPreparationProcess">Parameter componentMaterialPreparationProcess merupakan model dari component material preparation process</param>
        /// <returns>Data berhasil dirubah</returns>
        public ActionResult EditMaterialPreparation(ComponentMaterialPreparationProcess componentMaterialPreparationProcess)
        {
            try
            {
                var componentMaterialPreparationData = db.ComponentMaterialPreparationProcesses.Find(componentMaterialPreparationProcess.ID);
                componentMaterialPreparationData.Value = componentMaterialPreparationProcess.Value;
                db.SaveChanges();

                return(Json(new { success = true, responseText = "Value successfully updated" }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                ViewBag.ErrorMessage = "An error occured, please check your data input and try again";
                ViewBag.Exception(ex);
            }
            return(View("Error"));
        }
예제 #3
0
        /// <summary>
        /// Method AddMaterialPreparation berfungsi untuk menambah material preparation
        /// </summary>
        /// <param name="componentID">Parameter componentID merupakan id dari component</param>
        /// <param name="componentViewModel">Parameter componentViewModel merupakan view model dari component</param>
        /// <param name="collection">Parameter collection merupakan parameter yang digunakan oleh object FormCollection</param>
        /// <returns>Jika data berhasil ditambahkan, maka web akan menavigasikan ke halaman detail component</returns>
        public ActionResult AddMaterialPreparation(int componentID, ComponentViewModel componentViewModel, FormCollection collection)
        {
            try
            {
                var username    = User.Identity.Name;
                var currentPage = collection.GetValues("currentPage");

                foreach (var materialPreparation in componentViewModel.SelectedMaterialPreparationProcess)
                {
                    var existingComponentMaterialPreparation = db.ComponentMaterialPreparationProcesses.Where(x => x.ComponentID == componentID && x.MaterialPreparationProcessID == materialPreparation).SingleOrDefault();

                    if (existingComponentMaterialPreparation != null)
                    {
                        ViewBag.ComponentID  = componentID.ToString();
                        ViewBag.ErrorMessage = "Can't add material preparation process, because" + "" + existingComponentMaterialPreparation.MaterialPreparationProcess.Name + "" + "already exist on this component";
                        return(View("Error"));
                    }
                    else
                    {
                        var newMaterialPreparationProcess = new ComponentMaterialPreparationProcess
                        {
                            ComponentID = componentID,
                            MaterialPreparationProcessID = materialPreparation,
                            Created        = DateTime.Now,
                            CreatedBy      = username,
                            LastModified   = DateTime.Now,
                            LastModifiedBy = username
                        };
                        db.ComponentMaterialPreparationProcesses.Add(newMaterialPreparationProcess);
                        db.SaveChanges();
                    }
                }
                return(RedirectToAction("Details", "Component", new { id = componentID, page = currentPage[0] }));
            }
            catch (Exception ex)
            {
                ViewBag.ErrorMessage = "An error occured, please check your data input and try again";
                ViewBag.Exception    = ex;
            }
            return(View("Error"));
        }