Exemple #1
0
        public ActionResult GetCommodityView()
        {
            CommodityModel model       = new CommodityModel();
            var            CommodityId = Request.QueryString["commodityid"];

            try
            {
                CommodityClient = new CommodityServiceClient();
                CommodityDto cmdto = CommodityClient.GetById(CommodityId != null ? Convert.ToInt32(CommodityId) : 0);
                model.CommodityId = cmdto.CommodityId;
                model.CommoditiesInCommodityClass = cmdto.CommoditiesInCommodityClass;
                model.Name               = cmdto.Name;
                model.BotanicalName      = cmdto.BotanicalName;
                model.IsActive           = cmdto.IsActive;
                model.Image              = (((!String.IsNullOrEmpty(cmdto.Image)) ? Constants.IMAGEUPLOADPATHCOMMODITY + cmdto.Image : Constants.BLANKIMAGEPATH)).Replace("~/", "../../");
                model.CommodityClassList = GetCommodityClassList();
            }
            catch (Exception ex)
            {
                return(View("ErrorPage"));
            }
            finally
            {
                if (CommodityClient != null)
                {
                    CommodityClient.Close();
                }
            }
            return(View("CommodityView", model));
        }
Exemple #2
0
        public List <CommodityDto> GetCommodityList()
        {
            CommodityClient = new CommodityServiceClient();
            var CommodityDtos = CommodityClient.FindAll();

            CommodityClient.Close();
            return(CommodityDtos.Entities.ToList());
        }
Exemple #3
0
        public CommodityDto GetCommodityByClassId(CommodityDto CommoditymasterDto)
        {
            CommodityClient = new CommodityServiceClient();
            Query     query           = new Query();
            Criterion criteriaClassID = new Criterion("commodityclass.CommodityClassId", CommoditymasterDto.CommoditiesInCommodityClass.CommodityClassId, CriteriaOperator.Equal);

            query.Add(criteriaClassID);
            query.AddAlias(new Alias("commodityclass", "CommoditiesInCommodityClass"));
            var commoditydtos = CommodityClient.FindByQuery(query);

            CommodityClient.Close();
            return(commoditydtos.Entities.FirstOrDefault());
        }
Exemple #4
0
        public ActionResult AddCommodityIndex()
        {
            CommodityModel model       = new CommodityModel();
            string         mode        = Request.QueryString["mode"] != null ? Request.QueryString["mode"].ToString() : string.Empty;
            var            CommodityId = Request.QueryString["commodityid"] != null ? Request.QueryString["commodityid"] : null;

            try
            {
                if (mode == "edit")
                {
                    FormMode        = mode;
                    CommodityClient = new CommodityServiceClient();
                    CommodityDto cmdto = CommodityClient.GetById(CommodityId != null ? Convert.ToInt32(CommodityId) : 0);
                    Id = cmdto.CommodityId;
                    model.CommoditiesInCommodityClass = cmdto.CommoditiesInCommodityClass;
                    model.CommodityClassId            = cmdto.CommoditiesInCommodityClass.CommodityClassId;
                    model.Name               = cmdto.Name;
                    model.BotanicalName      = cmdto.BotanicalName;
                    model.IsActive           = cmdto.IsActive;
                    model.Image              = (((!String.IsNullOrEmpty(cmdto.Image)) ? Constants.IMAGEUPLOADPATHCOMMODITY + (Session["UploadedImageFileName"] = cmdto.Image).ToString() : Constants.BLANKIMAGEPATH)).Replace("~/", "../../");
                    model.CommodityClassList = GetCommodityClassList();
                }
                else
                {
                    model.Image = Constants.BLANKIMAGEPATH.Replace("~/", "../../");
                    model.CommodityClassList = GetCommodityClassList();
                }
            }
            catch (Exception ex)
            {
                return(View("ErrorPage"));
            }
            finally
            {
                if (CommodityClient != null)
                {
                    CommodityClient.Close();
                }
            }
            return(View("AddCommodity", model));
        }
Exemple #5
0
        public ActionResult AddCommodity(CommodityModel model)
        {
            ViewData["Error"]   = null;
            TempData["Success"] = null;
            try
            {
                if ((Session["UploadedImageFileName"] != null) && ModelState.IsValid)
                {
                    UserDto      currentUserDto     = (UserDto)Session[Constants.SKCURRENTUSER];
                    CommodityDto CommoditymasterDto = new CommodityDto();

                    CClassClient = new CommodityClassServiceClient();
                    CommoditymasterDto.CommoditiesInCommodityClass = CClassClient.GetById(model.CommodityClassId);
                    CommoditymasterDto.Name          = model.Name;
                    CommoditymasterDto.BotanicalName = model.BotanicalName;
                    CommoditymasterDto.Image         = Session["UploadedImageFileName"].ToString();
                    CommoditymasterDto.IsActive      = model.IsActive;
                    CommoditymasterDto.ModifiedBy    = currentUserDto.UserId;
                    CommodityClient = new CommodityServiceClient();

                    if (FormMode == "edit")
                    {
                        CommoditymasterDto.CommodityId = Id;
                        CommoditymasterDto             = CommodityClient.Update(CommoditymasterDto, currentUserDto.UserName);
                    }
                    else
                    {
                        CommoditymasterDto.CreatedBy = currentUserDto.UserId;
                        CommoditymasterDto           = CommodityClient.Create(CommoditymasterDto, currentUserDto.UserName);
                    }


                    //ResXResourceWriter writer = new ResXResourceWriter(@"\..\Resources.resx");
                    if (CommoditymasterDto.Response.HasWarning)
                    {
                        int i = 0;
                        foreach (BusinessWarning bw in CommoditymasterDto.Response.BusinessWarnings)
                        {
                            switch (bw.Message)
                            {
                            case Constants.BRBOTANICALNAMEVALIDATION:
                                CommodityDto ExistingCommodityDto = GetCommodityByClassId(CommoditymasterDto);
                                ModelState.AddModelError("err" + (++i).ToString(), string.Format(ErrorAndValidationMessages.BRBotanicalNameValidation, ExistingCommodityDto.Name));
                                break;

                            case Constants.BRCOMMODITYNAMEVALIDATION:
                                ModelState.AddModelError("err" + (++i).ToString(), string.Format(ErrorAndValidationMessages.BRCommodityNameValidation));
                                break;
                            }
                        }
                    }
                    else
                    {
                        if (FormMode == "edit")
                        {
                            TempData["StateSaved"] = string.Format(ClientResources.UpdateCommoditySaved, CommoditymasterDto.Name);
                        }
                        else
                        {
                            TempData["StateSaved"] = string.Format(ClientResources.AddCommoditySaved, CommoditymasterDto.Name, CommoditymasterDto.CommoditiesInCommodityClass.Name);
                        }

                        FormMode = string.Empty;
                        return(RedirectToAction("CommodityListIndex", "Masters"));
                    }
                }
                else
                {
                    ModelState.AddModelError(" ", ErrorAndValidationMessages.AddCommodityImageRequired);
                }
                model.CommodityClassList = GetCommodityClassList();
            }
            catch (Exception ex)
            {
                return(View("ErrorPage"));
            }
            finally
            {
                if (CommodityClient != null)
                {
                    CommodityClient.Close();
                }
            }
            //ViewData["imagepath"] = Constants.IMAGEUPLOADPATHCOMMODITY + Session["UploadedImageFileName"].ToString();
            return(View("AddCommodity", model));
        }