public async Task PUT_Updates_Data()
        {
            var controller = new UnitOfMeasuresController(Context);

            ConfigureRequest(controller);

            var model = new UnitOfMeasureModel
            {
                Id           = Guid.Parse("{69EA67A4-C575-472B-B463-C156E5BA61F3}"),
                Name         = "Test No Id",
                Abbreviation = "TNI"
            };

            //setup database record
            Context.UnitsOfMeasure.Add(new UnitOfMeasure
            {
                Id           = model.Id,
                Name         = model.Name,
                Abbreviation = model.Abbreviation
            });
            Context.SaveChanges();

            model.Name         = "My New Name";
            model.Abbreviation = "MNN";

            var result = await GetData <UnitOfMeasureModel>(controller.Put(model));

            Assert.AreEqual(model.Name, result.Name);
            Assert.AreEqual(model.Abbreviation, result.Abbreviation);
        }
Exemple #2
0
 public ActionResult Edit(UnitOfMeasureModel model)
 {
     try
     {
         if (!ModelState.IsValid)
         {
             model = GetDetail(model.Id);
             Response.StatusCode = (int)HttpStatusCode.BadRequest;
             return(PartialView("_Edit", model));
         }
         model.UpdatedDate    = DateTime.Now;
         model.UpdatedBy      = CurrentUser.UserName;
         model.OrganizationId = CurrentUser.ListOrganizationId[0];
         //====================
         string msg    = "";
         var    result = _factory.Update(model, ref msg);
         if (result)
         {
             return(RedirectToAction("Index"));
         }
         else
         {
             ModelState.AddModelError("Code", msg);
             Response.StatusCode = (int)HttpStatusCode.BadRequest;
             return(PartialView("_Edit", model));
         }
     }
     catch (Exception ex)
     {
         _logger.Error("UOMEdit: " + ex);
         return(new HttpStatusCodeResult(400, ex.Message));
     }
 }
Exemple #3
0
        public ActionResult Create(UnitOfMeasureModel model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(View(model));
                }
                string msg = "";
                model.CreatedBy      = CurrentUser.UserName;
                model.UpdatedBy      = CurrentUser.UserName;
                model.CreatedDate    = DateTime.Now;
                model.UpdatedDate    = DateTime.Now;
                model.OrganizationId = CurrentUser.ListOrganizationId[0];

                bool   result = _factory.Insert(model, ref msg);
                string msg1   = msg;
                if (result)
                {
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("Code", msg);
                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                _logger.Error("UOMCreate: " + ex);
                return(new HttpStatusCodeResult(400, ex.Message));
            }
        }
Exemple #4
0
        public ResultModels InsertUnit(UnitOfMeasureModel model)
        {
            ResultModels result = new ResultModels();

            result.IsOk = true;
            using (var cxt = new NuWebContext())
            {
                //check code
                var itemDb = cxt.I_UnitOfMeasure.Where(ww => ww.Code.ToUpper() == model.Code.Trim().ToUpper()).FirstOrDefault();
                if (itemDb != null)
                {
                    result.IsOk    = false;
                    result.Message = "UOM is exist!";
                    return(result);
                }
                var item = new I_UnitOfMeasure();
                item.Id          = Guid.NewGuid().ToString();
                item.Code        = item.Code.Trim();
                item.Name        = item.Name;
                item.IsActive    = item.IsActive;
                item.UpdatedBy   = item.UpdatedBy;
                item.UpdatedDate = DateTime.Now;
                item.CreatedBy   = item.CreatedBy;
                item.CreatedDate = item.CreatedDate;
                item.Status      = (int)Commons.EStatus.Actived;
                cxt.I_UnitOfMeasure.Add(item);
                cxt.SaveChanges();
            }

            return(result);
        }
        public async Task PUT_Is_OK()
        {
            var controller = new UnitOfMeasuresController(Context);

            ConfigureRequest(controller);

            var model = new UnitOfMeasureModel
            {
                Id           = Guid.Parse("{69EA67A4-C575-472B-B463-C156E5BA61F3}"),
                Name         = "Test No Id",
                Abbreviation = "TNO"
            };

            //setup database record
            Context.UnitsOfMeasure.Add(new UnitOfMeasure
            {
                Id           = model.Id,
                Name         = model.Name,
                Abbreviation = model.Abbreviation
            });
            Context.SaveChanges();

            var result = await GetResponse(controller.Put(model));

            Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
        }
Exemple #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="UnitOfMeasureModel"/> class.
 /// This then caches the save and cancel commands so that it can
 /// notify any views based on them.
 /// </summary>
 /// <param name="save">The save command that is based on this unit.</param>
 /// <param name="cancel">The cancel command that is based on this unit.</param>
 public UnitOfMeasureViewModel(UnitOfMeasureModel model, AsyncCommand save, AsyncCommand cancel)
     : this(save, cancel)
 {
     this.Id           = model.Id;
     this.FullName     = model.Name;
     this.Abbreviation = model.Abbreviation;
     this.IsDeleted    = model.IsDeleted;
 }
Exemple #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="UnitOfMeasureScreenViewModel"/> class.
        /// This also sets up all commands and data objects in the view.
        /// </summary>
        public UnitOfMeasureScreenViewModel()
        {
            this.Cancel = new AsyncCommand(
                (obj) =>
            {
                this.Selected    = null;
                this.CurrentUnit = new UnitOfMeasureViewModel(this.Save, this.Cancel);
            }, this.CanCancel);

            this.Save = new AsyncCommand(
                async(obj) =>
            {
                var model = new UnitOfMeasureModel
                {
                    Id           = this.currentUnit.Id,
                    Name         = this.currentUnit.FullName,
                    Abbreviation = this.currentUnit.Abbreviation,
                    IsDeleted    = this.currentUnit.IsDeleted
                };

                var existing = this.Units.FirstOrDefault(u => u.Id == this.currentUnit.Id);
                if (existing == null)
                {
                    model = await base.Api.PostAsync <UnitOfMeasureModel>(Constants.Endpoints.Units, model);
                    if (model == null)
                    {
                        //error saving, so show field error and return.
                        return;
                    }

                    var newCopy = new UnitOfMeasureViewModel(model, Save, Cancel);
                    this.Units.Add(newCopy);
                }
                else
                {
                    model = await base.Api.PutAsync <UnitOfMeasureModel>(Constants.Endpoints.Units, model);
                    if (model == null)
                    {
                        //error saving, so show field error and return.
                        return;
                    }

                    existing.FullName     = model.Name;
                    existing.Abbreviation = model.Abbreviation;
                    existing.IsDeleted    = model.IsDeleted;
                    existing.SetModificationType(ModificationType.Update);
                }

                this.CurrentUnit = new UnitOfMeasureViewModel(this.Save, this.Cancel);
                this.Selected    = null;
            }, this.ValidateInput);

            this.Units       = new ObservableCollection <UnitOfMeasureViewModel>();
            this.CurrentUnit = new UnitOfMeasureViewModel(this.Save, this.Cancel);
            this.Crumbs.Add(new BreadcrumbItemModel("Admin", this.GoToAdmin));
            this.Crumbs.Add(new BreadcrumbItemModel("Unit of Measure"));
        }
        public UnitOfMeasureModel Edit(UnitOfMeasureModel item)
        {
            var data = item.ConvertToData();

            using (_unitOfWorkFactory.Create())
            {
                _repository.Update(data);
            }
            return(data.ConvertToModel());
        }
        public JsonResult GetDefaultUoMByType(string typeCode = "")
        {
            UnitOfMeasureModel model = new UnitOfMeasureModel();

            using (UnitOfMeasureService svc = new UnitOfMeasureService())
            {
                var dto = svc.GetDefaultByTypeCode(typeCode);
                model = Mapper.Map <UnitOfMeasureDto, UnitOfMeasureModel>(dto);
            }
            return(Json(model, JsonRequestBehavior.AllowGet));
        }
        private UnitOfMeasureModel Create(UnitOfMeasureModel item)
        {
            var data = item.ConvertToData();

            using (_unitOfWorkFactory.Create())
            {
                _repository.Add(data);
            }


            return(data.ConvertToModel());
        }
 private static UnitOfMeasureModel Bind(TPO.DL.Models.UnitOfMeasure entity, UnitOfMeasureModel to)
 {
     to.ID                  = entity.ID;
     to.Code                = entity.Code;
     to.Description         = entity.Description;
     to.UnitOfMeasureTypeID = entity.TypeID;
     to.EnteredBy           = entity.EnteredBy;
     to.DateEntered         = entity.DateEntered;
     to.ModifiedBy          = entity.ModifiedBy;
     to.LastModified        = entity.LastModified;
     return(to);
 }
        public static UnitOfMeasure ConvertToData(this UnitOfMeasureModel data)
        {
            var model = new UnitOfMeasure();

            model.CreatedDate = data.CreatedDate;
            model.Id          = data.Id;
            model.IsActive    = data.IsActive;
            model.Name        = data.Name;
            model.DisplayName = data.DisplayName;

            return(model);
        }
Exemple #13
0
 public UnitOfMeasureModel GetDetail(string id)
 {
     try
     {
         UnitOfMeasureModel model = _factory.GetDetail(id);
         return(model);
     }
     catch (Exception ex)
     {
         _logger.Error("UOMDetail: " + ex);
         return(null);
     }
 }
        public UnitOfMeasureModel GetUnitOfMeasureByID(int id)
        {
            UnitOfMeasureModel model = null;

            using (TPO.DL.Repositories.ReferenceDataRepository repo = new DL.Repositories.ReferenceDataRepository())
            {
                var entity = repo.GetUnitOfMeasureByID(id);
                if (entity != null)
                {
                    model = Bind(entity, new UnitOfMeasureModel());
                }
            }
            return(model);
        }
Exemple #15
0
        public bool Insert(UnitOfMeasureModel model, ref string msg)
        {
            bool result = true;

            using (NuWebContext cxt = new NuWebContext())
            {
                try
                {
                    //if (cxt.I_UnitOfMeasure.Where(xx => xx.Code == model.Code).Select(ss => ss.Code).SingleOrDefault() != null)
                    //{
                    //    msg = "UOM code already exist, please input another one!";
                    //    return false;
                    //}

                    var itemExsit = cxt.I_UnitOfMeasure.Any(x => x.Code.ToLower().Equals(model.Code.ToLower()) && x.Status != (int)Commons.EStatus.Deleted && x.OrganizationId == model.OrganizationId);
                    if (itemExsit)
                    {
                        msg = _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("UOM Code") + " [" + model.Code + "] " + _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("is duplicated");
                        return(false);
                    }
                    if (string.IsNullOrEmpty(model.Name))
                    {
                        model.Name = model.Code;
                    }

                    I_UnitOfMeasure item = new I_UnitOfMeasure();

                    item.Id             = Guid.NewGuid().ToString();
                    item.Code           = model.Code;
                    item.Name           = model.Name;
                    item.IsActive       = model.IsActive;
                    item.CreatedBy      = model.CreatedBy;
                    item.CreatedDate    = model.CreatedDate;
                    item.UpdatedBy      = model.UpdatedBy;
                    item.UpdatedDate    = model.UpdatedDate;
                    item.OrganizationId = model.OrganizationId;
                    item.Description    = model.Description;
                    item.Status         = (int)Commons.EStatus.Actived;

                    cxt.I_UnitOfMeasure.Add(item);
                    cxt.SaveChanges();
                }
                catch (Exception ex)
                {
                    _logger.Error(ex);
                }
            }

            return(result);
        }
        public async Task PUT_Is_Bad_Request_Missing_Id()
        {
            var controller = new UnitOfMeasuresController(Context);

            ConfigureRequest(controller);

            var model = new UnitOfMeasureModel {
                Name = "Test No Id"
            };

            var result = await GetResponse(controller.Put(model));

            Assert.AreEqual(HttpStatusCode.BadRequest, result.StatusCode);
        }
        public async Task POST_Is_OK()
        {
            var controller = new UnitOfMeasuresController(Context);

            ConfigureRequest(controller);

            var model = new UnitOfMeasureModel
            {
                Name = "Test No Id"
            };

            var result = await GetResponse(controller.Post(model));

            Assert.AreEqual(HttpStatusCode.OK, result.StatusCode);
        }
Exemple #18
0
        public bool Update(UnitOfMeasureModel model, ref string msg)
        {
            bool result = true;

            using (NuWebContext cxt = new NuWebContext())
            {
                try
                {
                    var itemExsit = cxt.I_UnitOfMeasure.Where(x => x.Code.ToLower().Equals(model.Code.ToLower()) && x.Status != (int)Commons.EStatus.Deleted && x.OrganizationId == model.OrganizationId).FirstOrDefault();
                    if (itemExsit != null)
                    {
                        if (!itemExsit.Id.Equals(model.Id))
                        {
                            msg = _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("UOM Code") + " [" + model.Code + "] " + _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("is duplicated");
                            return(false);
                        }
                    }
                    if (string.IsNullOrEmpty(model.Name))
                    {
                        model.Name = model.Code;
                    }

                    var itemUpdate = (from tb in cxt.I_UnitOfMeasure
                                      where tb.Id == model.Id
                                      select tb).FirstOrDefault();
                    itemUpdate.Code        = model.Code;
                    itemUpdate.Name        = model.Name;
                    itemUpdate.IsActive    = model.IsActive;
                    itemUpdate.UpdatedBy   = model.UpdatedBy;
                    itemUpdate.UpdatedDate = model.UpdatedDate;
                    itemUpdate.Description = model.Description;
                    cxt.SaveChanges();
                }
                catch (Exception ex)
                {
                    _logger.Error(ex);
                    result = false;
                }
                finally
                {
                    if (cxt != null)
                    {
                        cxt.Dispose();
                    }
                }
            }
            return(result);
        }
Exemple #19
0
        public async Task <IHttpActionResult> Put(UnitOfMeasureModel updated)
        {
            if (updated == null)
            {
                return(this.BadRequest("Model must not be null."));
            }

            var results = await this.datasource.UpdateAsync(updated);

            if (results == null)
            {
                return(this.BadRequest("The record could not be updated."));
            }

            return(this.Ok(results));
        }
Exemple #20
0
        public async Task <IHttpActionResult> Post(UnitOfMeasureModel newModel)
        {
            if (newModel == null)
            {
                return(this.BadRequest("Model must not be null."));
            }

            var results = await this.datasource.InsertAsync(newModel);

            if (results == null)
            {
                return(this.BadRequest("The record could not be inserted."));
            }

            return(this.Ok(results));
        }
Exemple #21
0
        public ActionResult Export(UnitOfMeasureModel model)
        {
            try
            {
                if (model.ListStores == null)
                {
                    ModelState.AddModelError("ListStores", _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Please choose store") + ".");
                    return(View(model));
                }

                XLWorkbook wb = new XLWorkbook();
                var        ws = wb.Worksheets.Add("Sheet1");

                StatusResponse response = _factory.Export(ref ws, model.ListStores, CurrentUser.ListOrganizationId);

                if (!response.Status)
                {
                    ModelState.AddModelError("", response.MsgError);
                    return(View(model));
                }

                ViewBag.wb = wb;
                Response.Clear();
                Response.ClearContent();
                Response.ClearHeaders();
                Response.Charset         = System.Text.UTF8Encoding.UTF8.WebName;
                Response.ContentEncoding = System.Text.UTF8Encoding.UTF8;
                Response.ContentType     = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                Response.AddHeader("content-disposition", String.Format(@"attachment;filename={0}.xlsx", CommonHelper.GetExportFileName("UOM").Replace(" ", "_")));

                using (var memoryStream = new System.IO.MemoryStream())
                {
                    wb.SaveAs(memoryStream);
                    memoryStream.WriteTo(HttpContext.Response.OutputStream);
                    memoryStream.Close();
                }
                HttpContext.Response.End();
                return(RedirectToAction("Export"));
            }
            catch (Exception e)
            {
                _logger.Error("UOMExport: " + e);
                //return new HttpStatusCodeResult(400, e.Message);
                ModelState.AddModelError("ListStores", _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Export file have error") + ".");
                return(View(model));
            }
        }
        public async Task POST_Inserts_Records()
        {
            var controller = new UnitOfMeasuresController(Context);

            ConfigureRequest(controller);

            var initialCount = Context.UnitsOfMeasure.Count();

            var model = new UnitOfMeasureModel
            {
                Name         = "Test No Id",
                Abbreviation = "TNI"
            };

            var result = await GetData <UnitOfMeasureModel>(controller.Post(model));

            Assert.IsNotNull(result);
            Assert.AreNotEqual(Guid.Empty, result.Id);
            Assert.AreEqual(model.Name, result.Name);
            Assert.AreEqual(model.Abbreviation, result.Abbreviation);
        }
        public async Task POST_Fails_Duplicate_Records()
        {
            var controller = new UnitOfMeasuresController(Context);

            ConfigureRequest(controller);

            var model = new UnitOfMeasureModel
            {
                Name = "Test No Id"
            };

            Context.UnitsOfMeasure.Add(new UnitOfMeasure
            {
                Name = model.Name
            });
            Context.SaveChanges();

            var result = await GetResponse(controller.Post(model));

            Assert.AreEqual(HttpStatusCode.BadRequest, result.StatusCode);
        }
Exemple #24
0
 public ActionResult Delete(UnitOfMeasureModel model)
 {
     try
     {
         string msg    = "";
         var    result = _factory.Delete(model.Id, ref msg);
         if (!result)
         {
             ModelState.AddModelError("Name", msg);
             Response.StatusCode = (int)HttpStatusCode.BadRequest;
             return(PartialView("_Delete", model));
         }
         return(new HttpStatusCodeResult(HttpStatusCode.OK));
     }
     catch (Exception ex)
     {
         _logger.Error("UOMDelete: " + ex);
         ModelState.AddModelError("Name", _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Have an error when you delete an UOM"));
         Response.StatusCode = (int)HttpStatusCode.BadRequest;
         return(PartialView("_Delete", model));
     }
 }
Exemple #25
0
        //public List<UnitOfMeasureModel> _GetTables()
        //{
        //    using (NuWebContext cxt = new NuWebContext())
        //    {
        //        try
        //        {
        //            var lstResult = (from uom in cxt.I_UnitOfMeasure
        //                             select new UnitOfMeasureModel()
        //                             {
        //                                 Id = uom.Id,
        //                                 Code = uom.Code,
        //                                 Name = uom.Name,
        //                                 IsActive = uom.IsActive,
        //                                 CreatedBy = uom.CreatedBy,
        //                                 CreatedDate = uom.CreatedDate,
        //                                 UpdatedBy = uom.UpdatedBy,
        //                                 UpdatedDate = uom.UpdatedDate,
        //                                 OrganizationId = uom.OrganizationId,
        //                                 Description = uom.Description
        //                             }).ToList();
        //            return lstResult;
        //        }
        //        catch (Exception ex)
        //        {
        //            _logger.Error(ex.Message);
        //            return null;
        //        }
        //    }
        //}

        public StatusResponse Import(string filePath, ref ImportModel importModel, ref string msg, UserSession User)
        {
            StatusResponse Response = new StatusResponse();

            using (NuWebContext cxt = new NuWebContext())
            {
                using (var transaction = cxt.Database.BeginTransaction())
                {
                    DataTable dtUOM        = ReadExcelFile(filePath, "Sheet1");
                    string    tmpExcelPath = HttpContext.Current.Server.MapPath("~/ImportExportTemplate") + "/SBUnitOfMeasure.xlsx";
                    DataTable dtTmpUOM     = ReadExcelFile(@tmpExcelPath, "Sheet1");
                    if (dtUOM.Columns.Count != dtTmpUOM.Columns.Count)
                    {
                        msg = _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey(Commons._MsgDoesNotMatchFileExcel);
                        return(Response);
                    }
                    //========
                    bool   flagInsert = true;
                    string msgError   = "";

                    ImportItem itemErr = null;

                    List <UnitOfMeasureModel> Models   = new List <UnitOfMeasureModel>();
                    UnitOfMeasureModel        UOMModel = null;
                    foreach (DataRow item in dtUOM.Rows)
                    {
                        flagInsert = true;
                        msgError   = "";

                        if (item[0].ToString().Equals(""))
                        {
                            continue;
                        }

                        int index = int.Parse(item[0].ToString());

                        UOMModel             = new UnitOfMeasureModel();
                        UOMModel.Id          = Guid.NewGuid().ToString();
                        UOMModel.Code        = item[1].ToString().Trim().Replace("  ", " ");
                        UOMModel.Name        = item[2].ToString().Trim().Replace("  ", " ");
                        UOMModel.Description = item[3].ToString();
                        UOMModel.IsActive    = GetBoolValue(item[4].ToString());

                        UOMModel.CreatedBy      = User.UserName;
                        UOMModel.CreatedDate    = DateTime.Now;
                        UOMModel.UpdatedBy      = User.UserName;
                        UOMModel.UpdatedDate    = DateTime.Now;
                        UOMModel.OrganizationId = User.ListOrganizationId[0];
                        UOMModel.Status         = (int)Commons.EStatus.Actived;

                        if (string.IsNullOrEmpty(UOMModel.Code))
                        {
                            flagInsert = false;
                            msgError  += "<br/>" + _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("UOM Code is required");
                        }
                        if (string.IsNullOrEmpty(UOMModel.Name))
                        {
                            flagInsert = false;
                            msgError  += "<br/>" + _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("UOM Name is required");
                        }
                        //======================
                        if (flagInsert)
                        {
                            Models.Add(UOMModel);
                        }
                        else
                        {
                            itemErr      = new ImportItem();
                            itemErr.Name = UOMModel.Name;
                            itemErr.ListFailStoreName.Add("");
                            itemErr.ListErrorMsg.Add("Row: " + UOMModel.Index + msgError);
                            importModel.ListImport.Add(itemErr);
                        }
                    }
                    //=================
                    Response.Status = true;
                    try
                    {
                        var lstCodes  = Models.Select(ss => ss.Code.ToLower()).ToList();
                        var lstExists = cxt.I_UnitOfMeasure.Where(ww => lstCodes.Contains(ww.Code.ToLower()) &&
                                                                  User.ListOrganizationId.Contains(ww.OrganizationId) &&
                                                                  ww.Status != (int)Commons.EStatus.Deleted).ToList();
                        if (lstExists != null && lstExists.Count > 0)
                        {
                            lstCodes = new List <string>();
                            foreach (var item in lstExists)
                            {
                                msgError     = string.Format(_AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("UOM Code") + " [{0}] " + _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("is exist") + "!", item.Code);
                                itemErr      = new ImportItem();
                                itemErr.Name = item.Name;
                                itemErr.ListFailStoreName.Add("");
                                itemErr.ListErrorMsg.Add(_AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Row") + ": " + msgError);
                                importModel.ListImport.Add(itemErr);

                                lstCodes.Add(item.Code);
                            }
                        }

                        //Models = Models.Where(x => !lstCodes.Contains(x.Code)).ToList();
                        if (importModel.ListImport.Count == 0)
                        {
                            List <I_UnitOfMeasure> lstSave = new List <I_UnitOfMeasure>();
                            I_UnitOfMeasure        item    = null;
                            foreach (var model in Models)
                            {
                                item                = new I_UnitOfMeasure();
                                item.Id             = model.Id;
                                item.Code           = model.Code;
                                item.Name           = model.Name;
                                item.Description    = model.Description;
                                item.OrganizationId = model.OrganizationId;

                                item.CreatedBy   = model.CreatedBy;
                                item.CreatedDate = model.CreatedDate;
                                item.UpdatedDate = model.UpdatedDate;
                                item.UpdatedBy   = model.UpdatedBy;
                                item.IsActive    = model.IsActive;
                                item.Status      = (int)Commons.EStatus.Actived;

                                lstSave.Add(item);
                            }
                            cxt.I_UnitOfMeasure.AddRange(lstSave);
                            cxt.SaveChanges();
                            transaction.Commit();

                            //if (importModel.ListImport.Count == 0)
                            //{
                            ImportItem impItem = new ImportItem();
                            impItem.Name = "Import Unit Of Measurement Successful";
                            impItem.ListSuccessStoreName.Add("Import Unit Of Measurement Successful");
                            importModel.ListImport.Add(impItem);
                            //}
                            NSLog.Logger.Info("Import UOM Successful", lstSave);
                        }
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        //_logger.Error(ex);
                        NSLog.Logger.Error("Import UOM error", ex);
                    }
                }
            }
            return(Response);
        }
Exemple #26
0
        public ActionResult Create()
        {
            UnitOfMeasureModel model = new UnitOfMeasureModel();

            return(View(model));
        }
Exemple #27
0
 public static UnitOfMeasure ToEntity(this UnitOfMeasureModel model)
 {
     return(model.MapTo <UnitOfMeasureModel, UnitOfMeasure>());
 }
Exemple #28
0
        public PartialViewResult Delete(string id)
        {
            UnitOfMeasureModel model = GetDetail(id);

            return(PartialView("_Delete", model));
        }
Exemple #29
0
 public static UnitOfMeasure ToEntity(this UnitOfMeasureModel model, UnitOfMeasure destination)
 {
     return(model.MapTo(destination));
 }
Exemple #30
0
        public ActionResult Import(UnitOfMeasureModel model)
        {
            //try
            //{
            //    //if (model.ListStores == null)
            //    //{
            //    //    ModelState.AddModelError("ListStores", "Please choose store.");
            //    //    return View(model);
            //    //}
            //    if (model.ExcelUpload == null || model.ExcelUpload.ContentLength <= 0)
            //    {
            //        ModelState.AddModelError("ExcelUpload", "File excel cannot be null");
            //        return View(model);
            //    }

            //    ImportModel importModel = new ImportModel();
            //    string msg = "";
            //    string msg1 = "";

            //    StatusResponse response = _factory.Import(model.ExcelUpload, ref importModel, ref msg, ref msg1, CurrentUser);

            //    if (!response.Status)
            //    {
            //        ModelState.AddModelError("", response.MsgError);
            //        return View(model);
            //    }
            //    // Delete File Excel and File Zip Image
            //    CommonHelper.DeleteFileFromServer(CommonHelper.GetFilePath(model.ExcelUpload));
            //    //if (!ModelState.IsValid)
            //    //    return View(model);
            //    if (msg.Equals(""))
            //    {
            //        return View("ImportDetail", importModel);
            //    }
            //    else
            //    {
            //        _logger.Error("UOM_Import: " + msg);
            //        ModelState.AddModelError("ExcelUpload", msg);
            //        return View(model);
            //    }
            //}
            //catch (Exception e)
            //{
            //    _logger.Error("UOMImport: " + e);
            //    //return new HttpStatusCodeResult(400, e.Message);
            //    ModelState.AddModelError("ExcelUpload", "Import file have error.");
            //    return View(model);
            //}

            try
            {
                if (model.ExcelUpload == null || model.ExcelUpload.ContentLength <= 0)
                {
                    ModelState.AddModelError("ExcelUpload", _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey("Excel filename cannot be null"));
                    return(View(model));
                }

                ImportModel importModel = new ImportModel();
                string      msg         = "";
                if (model.ExcelUpload != null && model.ExcelUpload.ContentLength > 0)
                {
                    string fileName = Path.GetFileName(model.ExcelUpload.FileName);
                    string filePath = string.Format("{0}/{1}", System.Web.HttpContext.Current.Server.MapPath("~/Uploads"), fileName);
                    //upload file to server
                    if (System.IO.File.Exists(filePath))
                    {
                        System.IO.File.Delete(filePath);
                    }
                    model.ExcelUpload.SaveAs(filePath);

                    StatusResponse response = _factory.Import(filePath, ref importModel, ref msg, CurrentUser);
                    if (!response.Status)
                    {
                        ModelState.AddModelError("", response.MsgError);
                        return(View(model));
                    }
                }
                if (msg.Equals(""))
                {
                    return(View("ImportDetail", importModel));
                }
                else
                {
                    _logger.Error("UOMImport: " + msg);
                    ModelState.AddModelError("ExcelUpload", msg);
                    return(View(model));
                }
            }
            catch (Exception e)
            {
                _logger.Error("UOM: " + e);
                ModelState.AddModelError("ExcelUpload", _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey(e.Message));
                return(View(model));
            }
        }