public bool DeleteUnit(UnitTypeModel unitmodel)
        {
            Mapper.Initialize(map => { map.CreateMap <UnitTypeModel, UnitType>(); });
            var unitData = Mapper.Map <UnitType>(unitmodel);

            return(unitRepository.DeleteUnit(unitData));
        }
        // GET: UnitTypes
        public ActionResult UnitTypes(int?page)
        {
            UnitTypeModel model = new UnitTypeModel();

            model.pageNumber = (page == null ? 1 : Convert.ToInt32(page));
            int currentpage                  = model.pageNumber;
            int pageSize                     = Common.pagesize;
            int totalRowCount                = 0;
            List <UnitTypeModel> lst         = dal.BindData(currentpage, pageSize, out totalRowCount);
            List <UnitTypeModel> checkdelete = new List <UnitTypeModel>();

            foreach (var u in lst)
            {
                bool check = dal.CheckDelete(u.ID);
                u.IsDelete = check;
                checkdelete.Add(u);
            }
            model.unittypes = checkdelete;
            if (lst.Count > 0)
            {
                List <ListItem> pager = Common.generatePager(totalRowCount, pageSize, currentpage);
                model.dlpager = pager;
            }
            return(View(model));
        }
        public void Edit(UnitTypeModel unittypemodel)
        {
            Mapper.Initialize(map => { map.CreateMap <UnitTypeModel, UnitType>(); });
            var unitData = Mapper.Map <UnitType>(unittypemodel);

            unitRepository.Edit(unitData);
        }
        public void Insert(UnitTypeModel unittypemodel)
        {
            Mapper.Initialize(cfg => { cfg.CreateMap <UnitTypeModel, UnitType>(); });

            var unit = Mapper.Map <UnitType>(unittypemodel);

            unitRepository.Insert(unit);
        }
예제 #5
0
        public UnitModel Get(CompanyModel companyModel, UnitTypeModel unitTypeModel)
        {
            var model = Get(companyModel);

            model.TypeId = unitTypeModel.Id;

            return(model);
        }
        public ActionResult DeleteConfirmed(int id)
        {
            UnitTypeModel unitType = dal.FindbyID(id);

            db.UnitTypes.Remove(unitType);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
 public JsonResult UpdateUnit(UnitTypeModel unitmodel)
 {
     if (ModelState.IsValid)
     {
         unitService.Edit(unitmodel);
         return(Json(true, JsonRequestBehavior.AllowGet));
     }
     return(Json(false, JsonRequestBehavior.AllowGet));
 }
예제 #8
0
        public UnitTypeModel Get()
        {
            var model = new UnitTypeModel();

            model.Description = StringsGenerators.GenerateString(199);
            model.Name        = StringsGenerators.GenerateString(10);

            return(model);
        }
예제 #9
0
        public IActionResult Put(int id, [FromBody] UnitTypeModel updatedUnitType)
        {
            var unitType = _unitTypeService.Update(updatedUnitType.ToDomainModel());

            if (unitType == null)
            {
                return(NotFound());
            }
            return(Ok(unitType.ToApiModel()));
        }
 public ActionResult Edit([Bind(Include = "ID,Name,SortOrder,Type")] UnitTypeModel unitType)
 {
     if (ModelState.IsValid)
     {
         db.Entry(unitType).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(unitType));
 }
예제 #11
0
 public IActionResult Post([FromBody] UnitTypeModel unitType)
 {
     try
     {
         _unitTypeService.Add(unitType.ToDomainModel());
     }
     catch (System.Exception ex)
     {
         ModelState.AddModelError("AddUnitType", ex.GetBaseException().Message);
         return(BadRequest(ModelState));
     }
     return(CreatedAtAction("Get", new { Id = unitType.Id }, unitType));
 }
        public IActionResult AddNewUnitType([FromBody] UnitTypeModel model)
        {
            try
            {
                _unitTypeRepository.CreateUnitType(model);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(Ok(ex));
            }
        }
        public IActionResult GatUnitType(int unitTypeId)
        {
            try
            {
                UnitTypeModel unitType = _unitTypeRepository.GetUnitType(unitTypeId);

                return(Ok(unitType));
            }
            catch (Exception ex)
            {
                return(Ok(ex));
            }
        }
        public IActionResult UpdateUnitType(int unitTypeId, [FromBody] UnitTypeModel model)
        {
            try
            {
                model.Id = unitTypeId;
                _unitTypeRepository.UpdateUnitType(model);

                return(Ok());
            }
            catch (Exception ex)
            {
                return(Ok(ex));
            }
        }
        // GET: UnitTypes/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UnitTypeModel unitType = dal.FindbyID(id);

            if (unitType == null)
            {
                return(HttpNotFound());
            }
            return(View(unitType));
        }
        /// <summary>
        /// Saves the unit type.
        /// </summary>
        /// <param name="model">The model.</param>
        private void SaveUnitType(UnitTypeModel model)
        {
            UnitType unitType;

            if (model.Id.HasValue)
            {
                unitType = GetUnitTypeById(model.Id.Value);
                unitType.UnitTypeName = model.Name;
            }
            else
            {
                unitType = new UnitType {
                    UnitTypeName = model.Name
                };
                _context.UnitTypes.Add(unitType);
            }

            _context.SaveChanges();
        }
예제 #17
0
        public UnitTypeModel FindbyID(int?id)
        {
            UnitTypeModel model = new UnitTypeModel();

            try
            {
                model = (from u in db.UnitTypes
                         where u.ID == id
                         select new UnitTypeModel
                {
                    ID = u.ID,
                    Name = u.Name,
                    Type = u.Type.Value,
                    SortOrder = u.SortOrder.Value,
                    UTypeName = u.Type.Value == 1?"Size" : "Model"
                }).First();
            }
            catch
            { }
            return(model);
        }
        public JsonResult CreateUnitType(UnitTypeModel model)
        {
            if (!ModelState.IsValid)
            {
                return(Json(new
                {
                    Result = "ERROR",
                    Message = "Form is not valid! " +
                              "Please correct it and try again."
                }));
            }

            if (!User.IsInRole("Officer"))
            {
                return(Json(new
                {
                    Result = "ERROR",
                    Message = "You do not have the authority to create a new unit type."
                }));
            }

            try
            {
                JourListDMContainer dm = new JourListDMContainer();

                UnitType newUnitType = new UnitType();
                newUnitType.Description = model.Description;
                dm.AddToUnitTypes(newUnitType);
                dm.SaveChanges();

                model.Id = newUnitType.Id;

                return(Json(new { Result = "OK", Record = model }));
            }
            catch (Exception e)
            {
                return(Json(new { Result = "ERROR", Message = e.Message }));
            }
        }
        ////
        //// POST: /DataManagement/GetUnitOptions
        //[HttpPost]
        //public JsonResult GetUnitOptions()
        //{
        //    try
        //    {
        //        JourListDMContainer dm = new JourListDMContainer();
        //        var list = dm.Units.Select(z => new { DisplayText = z.Description, Value = z.Id });
        //        return Json(new { Result = "OK", Options = list });
        //    }
        //    catch (Exception e)
        //    {
        //        return Json(new { Result = "ERROR", Message = e.Message });
        //    }
        //}

        #endregion

        #region UnitType

        // POST: /DataManagement/UnitTypeList
        public JsonResult UnitTypeList()
        {
            try
            {
                JourListDMContainer  dm   = new JourListDMContainer();
                List <UnitTypeModel> list = new List <UnitTypeModel>();

                foreach (var a in dm.UnitTypes.Where(z => z.Active == true))
                {
                    UnitTypeModel item = new UnitTypeModel();
                    item.Id          = a.Id;
                    item.Description = a.Description;
                    item.Active      = a.Active;
                    list.Add(item);
                }

                return(Json(new { Result = "OK", Records = list }));
            }
            catch (Exception e)
            {
                return(Json(new { Result = "ERROR", Message = e.Message }));
            }
        }
        public JsonResult UpdateUnitType(UnitTypeModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Json(new
                    {
                        Result = "ERROR",
                        Message = "Form is not valid! " +
                                  "Please correct it and try again."
                    }));
                }

                if (!User.IsInRole("Officer"))
                {
                    return(Json(new
                    {
                        Result = "ERROR",
                        Message = "You do not have the authority to update this unit type."
                    }));
                }

                JourListDMContainer dm = new JourListDMContainer();

                UnitType item = dm.UnitTypes.Single(z => z.Id == model.Id);
                item.Description = model.Description;
                item.Active      = model.Active;
                dm.SaveChanges();

                return(Json(new { Result = "OK" }));
            }
            catch (Exception e)
            {
                return(Json(new { Result = "ERROR", Message = e.Message }));
            }
        }
 /// <summary>
 /// Updates the unit type.
 /// </summary>
 /// <param name="model">The model.</param>
 public void UpdateUnitType(UnitTypeModel model)
 {
     SaveUnitType(model);
 }
예제 #22
0
 protected UnitModel CreateUnit(CompanyModel companyModel, UnitTypeModel unitTypeModel)
 {
     return(_container.Resolve <IUnitService>()
            .Create(_container.Resolve <IUnitModelGenerator>().Get(companyModel, unitTypeModel))
            .Data);
 }
 /// <summary>
 /// Creates the unit type.
 /// </summary>
 /// <param name="model">The model.</param>
 public void CreateUnitType(UnitTypeModel model)
 {
     SaveUnitType(model);
 }
        public JsonResult DeleteUnits(UnitTypeModel unitmodel)
        {
            var result = unitService.DeleteUnit(unitmodel);

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
 public void Delete(UnitTypeModel unittypemodel)
 {
     throw new NotImplementedException();
 }