Exemple #1
0
        public ActionResult AddVendorType(VendorTypeViewModel model)
        {
            if (ModelState.IsValid)
            {
                VendorTypeMD result = null;
                try
                {
                    var vendortype = new VendorTypeMD();
                    vendortype.Type        = model.Type;
                    vendortype.Description = model.Description;
                    vendortype.CompanyId   = Convert.ToInt32(User.Identity.GetUserId());
                    vendortype.CreatedById = Convert.ToInt32(User.Identity.GetUserId());
                    vendortype.CreatedDate = DateTime.Now;

                    result = _vendorTypeService.AddVendorType(vendortype);
                    if (result.HasErrors)
                    {
                        model.HasErrorMessage = result.HasErrors;
                        model.MessageType     = result.ResultMessages.FirstOrDefault().MessageType;
                        model.Message         = result.ResultMessages.FirstOrDefault().Message;
                        return(View(model));
                    }
                }
                catch (Exception ex)
                {
                    if (!model.HasErrorMessage && result != null)
                    {
                        model.HasErrorMessage = result.HasErrors;
                        model.MessageType     = result.ResultMessages.FirstOrDefault().MessageType;
                        model.Message         = result.ResultMessages.FirstOrDefault().Message;
                    }
                }
            }
            return(View(model));
        }
Exemple #2
0
        public static VendorTypeMD Translate(this VendorTypeDE from)
        {
            var to = new VendorTypeMD();

            to.Id          = from.Id;
            to.Type        = from.Type;
            to.Description = from.Description;
            to.CreatedById = from.CreatedById;
            to.CompanyId   = from.CompanyId.Value;
            to.CreatedDate = from.CreatedDate;

            return(to);
        }
        public VendorTypeMD ModifyVendorType(VendorTypeMD mod)
        {
            var entity = mod.Translate();

            try
            {
                _VendorTypeRepo.Update(entity);
                _VendorTypeRepo.CommitAllChanges();
                mod.AddSuccessMessage(string.Format(AppConstants.CRUD_UPDATE, "VendorType"));
            }
            catch (Exception)
            {
                mod.AddSuccessMessage(string.Format(AppConstants.CRUD_UPDATE_ERROR, "VendorType"));
            }

            return(mod);
        }
        public VendorTypeMD AddVendorType(VendorTypeMD mod)
        {
            try
            {
                var entity = mod.Translate();
                _VendorTypeRepo.Insert(entity);
                _VendorTypeRepo.CommitAllChanges();
                mod.AddSuccessMessage(string.Format(AppConstants.CRUD_ADD, "VendorType"));
                mod.Id = entity.Id;
            }
            catch (Exception ex)
            {
                mod.HasErrors = true;
                mod.AddErrorMessage(string.Format(AppConstants.CRUD_ADD_ERROR, "VendorType"));
            }

            return(mod);
        }
        public VendorTypeMD DeleteVendorType(long id)
        {
            var mod = new VendorTypeMD();

            try
            {
                var VendorType = _VendorTypeRepo.Fetch(x => x.IsActive);
                VendorType.IsActive = false;
                _VendorTypeRepo.Update(VendorType);
                _VendorTypeRepo.CommitAllChanges();

                mod.AddSuccessMessage(string.Format(AppConstants.CRUD_DELETE, "VendorType"));
            }
            catch (Exception ex)
            {
                mod.AddErrorMessage(string.Format(AppConstants.CRUD_DELETE_ERROR, "VendorType"));
            }
            return(mod);
        }
Exemple #6
0
        public static List <VendorTypeMD> Translate(this List <VendorTypeDE> list)
        {
            var vendortypes = new List <VendorTypeMD>();

            foreach (var from in list)
            {
                var to = new VendorTypeMD();

                to.Id          = from.Id;
                to.Type        = from.Type;
                to.Description = from.Description;
                to.CreatedById = from.CreatedById;
                to.CompanyId   = from.CompanyId.Value;
                to.CreatedDate = from.CreatedDate;

                vendortypes.Add(to);
            }
            return(vendortypes);
        }
Exemple #7
0
        public static VendorTypeDE Translate(this VendorTypeMD from, VendorTypeDE dest = null)
        {
            var to = dest ?? new VendorTypeDE();

            if (to.Id <= 0)
            {
                to.Id       = from.Id;
                to.IsActive = true;
            }
            else
            {
                to.IsActive = from.IsActive;
            }
            to.Type        = from.Type;
            to.Description = from.Description;
            to.CreatedById = from.CreatedById;
            to.CompanyId   = from.CompanyId;
            to.CreatedDate = from.CreatedDate;


            return(to);
        }