Ejemplo n.º 1
0
        public CResult <bool> UpdateManufacturer(WebManufacturer model)
        {
            LogHelper.Info(MethodBase.GetCurrentMethod().ToString());
            LogHelper.Info("model", model);

            if (string.IsNullOrEmpty(model.ID))
            {
                return(new CResult <bool>(false, ErrorCode.ParameterError));
            }

            using (var context = new DeviceMgmtEntities())
            {
                var entity = context.Manufacturer.FirstOrDefault(t => t.ID == model.ID && t.IsValid);
                if (entity == null)
                {
                    return(new CResult <bool>(false, ErrorCode.ManufacturerNotExist));
                }

                if (context.Manufacturer.Any(t => t.Name.ToUpper() == model.Name.ToUpper() && t.ProjectID == entity.ProjectID && t.IsValid && t.ID != model.ID))
                {
                    return(new CResult <bool>(false, ErrorCode.ManufacturerNameIsExist));
                }

                entity.Name    = model.Name;
                entity.Note    = model.Note;
                entity.Address = model.Address;
                entity.Contact = model.Contact;
                entity.Mobile  = model.Mobile;
                entity.Phone   = model.Phone;

                context.Entry(entity).State = EntityState.Modified;
                return(context.Save());
            }
        }
 public ActionResult Edit(WebManufacturer webManufacturer)
 {
     try
     {
         var result = new ManufacturerBLL().UpdateManufacturer(webManufacturer);
         return(JsonContentHelper.GetJsonContent(result));
     }
     catch
     {
         return(View());
     }
 }
        public ActionResult Create(WebManufacturer WebManufacturer)
        {
            try
            {
                WebManufacturer.ProjectID    = this.GetCurrentProjectID();
                WebManufacturer.CreateUserID = this.GetCurrentUserID();

                var result = new ManufacturerBLL().InsertManufacturer(WebManufacturer);
                return(JsonContentHelper.GetJsonContent(result));
            }
            catch
            {
                return(View());
            }
        }
Ejemplo n.º 4
0
        public CResult <bool> InsertManufacturer(WebManufacturer model)
        {
            LogHelper.Info(MethodBase.GetCurrentMethod().ToString());
            LogHelper.Info("model", model);

            if (string.IsNullOrEmpty(model.ProjectID))
            {
                return(new CResult <bool>(false, ErrorCode.ParameterError));
            }

            using (var context = new DeviceMgmtEntities())
            {
                if (context.Project.Any(t => t.IsValid && t.ID == model.ProjectID) == false)
                {
                    return(new CResult <bool>(false, ErrorCode.ProjectNotExist));
                }

                if (context.Manufacturer.Any(t => t.Name.ToUpper() == model.Name.ToUpper() && t.ProjectID == model.ProjectID && t.IsValid))
                {
                    return(new CResult <bool>(false, ErrorCode.ManufacturerNameIsExist));
                }

                var entity = new Manufacturer();
                entity.CreateDate   = DateTime.Now;
                entity.CreateUserID = model.CreateUserID;
                entity.ID           = Guid.NewGuid().ToString();
                entity.Name         = model.Name;
                entity.IsValid      = true;
                entity.Note         = model.Note;
                entity.ProjectID    = model.ProjectID;
                entity.Address      = model.Address;
                entity.Contact      = model.Contact;
                entity.Mobile       = model.Mobile;
                entity.Phone        = model.Phone;

                context.Manufacturer.Add(entity);

                return(context.Save());
            }
        }
Ejemplo n.º 5
0
        public CResult <WebManufacturer> GetManufacturerByID(string manufacturerID)
        {
            LogHelper.Info(MethodBase.GetCurrentMethod().ToString());
            LogHelper.Info("manufacturerID", manufacturerID);

            if (string.IsNullOrEmpty(manufacturerID))
            {
                return(new CResult <WebManufacturer>(null, ErrorCode.ParameterError));
            }

            using (var context = new DeviceMgmtEntities())
            {
                var entity = context.Manufacturer.FirstOrDefault(t => t.ID == manufacturerID && t.IsValid);
                if (entity == null)
                {
                    return(new CResult <WebManufacturer>(null, ErrorCode.ManufacturerNotExist));
                }

                var model = new WebManufacturer()
                {
                    ID             = entity.ID,
                    Name           = entity.Name,
                    Address        = entity.Address,
                    Contact        = entity.Contact,
                    Mobile         = entity.Mobile,
                    Phone          = entity.Phone,
                    Note           = entity.Note,
                    CreateDate     = entity.CreateDate,
                    CreateUserID   = entity.CreateUserID,
                    CreateUserName = entity.User.Name,
                    ProjectID      = entity.ProjectID
                };

                LogHelper.Info("result", model);

                return(new CResult <WebManufacturer>(model));
            }
        }