Ejemplo n.º 1
0
        public static RequestResult Delete(List <string> selectedList)
        {
            RequestResult result = new RequestResult();

            try
            {
#if !DEBUG
                using (TransactionScope trans = new TransactionScope())
                {
#endif
                using (CFContext context = new CFContext())
                {
                    DeleteHelper.DeleteAbnormalReason(context, selectedList);

                    context.SaveChanges();
                }

#if !DEBUG
                trans.Complete();
            }
#endif
                result.ReturnSuccessMessage(string.Format("{0} {1} {2}", Resources.Resource.Delete, Resources.Resource.AbnormalReason, Resources.Resource.Success));
            }
            catch (Exception ex)
            {
                var err = new Error(MethodBase.GetCurrentMethod(), ex);

                Logger.Log(err);

                result.ReturnError(err);
            }

            return(result);
        }
Ejemplo n.º 2
0
        public static RequestResult ChangePassword(PasswordFormModel passwordFormModel, Account account)
        {
            RequestResult requestResult = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    var person = context.People.First(p => p.LoginId == account.Id);
                    if (string.Compare(person.Password, passwordFormModel.OriginalPassword, false) == 0)
                    {
                        person.Password       = passwordFormModel.NewPassword;
                        person.LastModifyTime = DateTime.Now;

                        context.SaveChanges();

                        requestResult.ReturnSuccessMessage(Resources.Resource.ChangePassword + " " + Resources.Resource.Success);
                    }
                    else
                    {
                        requestResult.ReturnFailedMessage(Resources.Resource.WrongPassword);
                    }
                }
            }
            catch (Exception e)
            {
                var error = new Error(MethodBase.GetCurrentMethod(), e);

                Logger.Log(error);

                requestResult.ReturnError(error);
            }

            return(requestResult);
        }
Ejemplo n.º 3
0
        public static RequestResult Create(CreateFormModel createFormModel)
        {
            RequestResult result = new RequestResult();

            try
            {
                if (createFormModel.FormInput.Type == Define.Other || createFormModel.FormInput.Type == Define.New)
                {
                    result.ReturnFailedMessage(string.Format("{0} {1}", Resources.Resource.Unsupported, Resources.Resource.AbnormalReasonType));
                }
                else
                {
                    using (CFContext context = new CFContext())
                    {
                        var exists = context.AbnormalReasons.FirstOrDefault(x => x.OrganizationId == new Guid(createFormModel.OrganizationId) && x.Type == createFormModel.FormInput.Type && x.ARId == createFormModel.FormInput.ARId);

                        if (exists == null)
                        {
                            Guid abnormalReasonId = Guid.NewGuid();

                            context.AbnormalReasons.Add(new CF.Models.Maintenance.AbnormalReason()
                            {
                                AbnormalReasonId = abnormalReasonId,
                                OrganizationId   = new Guid(createFormModel.OrganizationId),
                                Type             = createFormModel.FormInput.Type,
                                ARId             = createFormModel.FormInput.ARId,
                                Name             = createFormModel.FormInput.Name,
                                LastModifyTime   = DateTime.Now,
                                Solutions        = createFormModel.SolutionModels.Select(x => new CF.Models.Maintenance.Solution()
                                {
                                    SolutionId     = new Guid(x.SolutionId),
                                    SId            = x.SId,
                                    Name           = x.Name,
                                    Type           = x.Type,
                                    OrganizationId = new Guid(createFormModel.OrganizationId)
                                }).ToList(),
                            });

                            context.SaveChanges();

                            result.ReturnData(abnormalReasonId, string.Format("{0} {1} {2}", Resources.Resource.Create, Resources.Resource.AbnormalReason, Resources.Resource.Success));
                        }
                        else
                        {
                            result.ReturnFailedMessage(string.Format("{0} {1}", Resources.Resource.ARId, Resources.Resource.Exists));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var err = new Error(MethodBase.GetCurrentMethod(), ex);

                Logger.Log(err);

                result.ReturnError(err);
            }

            return(result);
        }
Ejemplo n.º 4
0
        public static RequestResult Delete(Guid organizationId)
        {
            RequestResult requestResult = new RequestResult();

            try
            {
                var organizationIds = GetDownStreamOrganizationIds(organizationId, true);

                using (CFContext context = new CFContext())
                {
                    DeleteHelper.DeleteOrganization(context, organizationIds);
                    context.SaveChanges();
                }

                requestResult.ReturnSuccessMessage(string.Format("{0} {1} {2}", Resources.Resource.Delete, Resources.Resource.Organization, Resources.Resource.Success));
            }
            catch (Exception e)
            {
                var error = new Error(MethodBase.GetCurrentMethod(), e);
                Logger.Log(error);
                requestResult.ReturnError(error);
                //throw;
            }

            return(requestResult);
        }
Ejemplo n.º 5
0
        public static RequestResult Delete(List <string> selectedList)
        {
            RequestResult requestResult = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    DeleteHelper.DeleteMaterial(context, selectedList);

                    context.SaveChanges();
                }

                requestResult.ReturnSuccessMessage(string.Format("{0} {1} {2}", Resources.Resource.Delete, Resources.Resource.Material, Resources.Resource.Success));
            }
            catch (Exception e)
            {
                var error = new Error(MethodBase.GetCurrentMethod(), e);

                Logger.Log(error);

                requestResult.ReturnError(error);
            }

            return(requestResult);
        }
Ejemplo n.º 6
0
 public void UpdateEndereco(Endereco endereco)
 {
     using (Context = new CFContext())
     {
         Context.Entry(endereco).State = EntityState.Modified;
         Context.SaveChanges();
     }
 }
Ejemplo n.º 7
0
 public void CreateEndereco(Endereco endereco)
 {
     using (Context = new CFContext())
     {
         Context.Enderecos.Add(endereco);
         Context.SaveChanges();
     }
 }
Ejemplo n.º 8
0
 public void UpdateUsuario(Usuario usuario)
 {
     using (Context = new CFContext())
     {
         Context.Entry(usuario).State = EntityState.Modified;
         Context.SaveChanges();
     }
 }
Ejemplo n.º 9
0
 public void CreateUsuario(Usuario usuario)
 {
     using (Context = new CFContext())
     {
         Context.Usuarios.Add(usuario);
         Context.SaveChanges();
     }
 }
Ejemplo n.º 10
0
        public static object Create(CreateFormModel createFormModel)
        {
            RequestResult result = new RequestResult();

            try
            {
                if (createFormModel.FormInput.EquipmentType == Define.New)
                {
                    result.ReturnFailedMessage(string.Format("{0} {1}", Resources.Resource.Unsupported, Resources.Resource.EquipmentType));
                }
                else
                {
                    using (CFContext context = new CFContext())
                    {
                        var exists = context.ESpecifications.FirstOrDefault(x => x.OrganizationId == new Guid(createFormModel.OrganizationId) && x.EquipmentType == createFormModel.FormInput.EquipmentType && x.Name == createFormModel.FormInput.Name);

                        if (exists == null)
                        {
                            Guid equipmentSpecificationId = Guid.NewGuid();

                            context.ESpecifications.Add(new CF.Models.Maintenance.ESpecification()
                            {
                                ESpecificationId = equipmentSpecificationId,
                                OrganizationId   = new Guid(createFormModel.OrganizationId),
                                EquipmentType    = createFormModel.FormInput.EquipmentType,
                                Name             = createFormModel.FormInput.Name
                            });

                            context.ESOptions.AddRange(createFormModel.FormInput.EquipmentSpecificationOptionModels.Select(x => new CF.Models.Maintenance.ESOption
                            {
                                ESOptionId       = Guid.NewGuid(),
                                ESpecificationId = equipmentSpecificationId,
                                Name             = x.Name,
                                Seq = x.Seq
                            }).ToList());

                            context.SaveChanges();

                            result.ReturnData(equipmentSpecificationId, string.Format("{0} {1} {2}", Resources.Resource.Create, Resources.Resource.EquipmentSpecification, Resources.Resource.Success));
                        }
                        else
                        {
                            result.ReturnFailedMessage(string.Format("{0} {1}", Resources.Resource.EquipmentSpecificationName, Resources.Resource.Exists));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var err = new Error(MethodBase.GetCurrentMethod(), ex);

                Logger.Log(err);

                result.ReturnError(err);
            }

            return(result);
        }
Ejemplo n.º 11
0
        public static object Edit(EditFormModel editFormModel)
        {
            RequestResult result = new RequestResult();

            try
            {
                if (editFormModel.FormInput.Type == Define.Other || editFormModel.FormInput.Type == Define.New)
                {
                    result.ReturnFailedMessage(string.Format("{0} {1}", Resources.Resource.Unsupported, Resources.Resource.SolutionType));
                }
                else
                {
                    using (CFContext context = new CFContext())
                    {
                        var solution = context.Solutions.First(x => x.SolutionId == new Guid(editFormModel.SolutionId));

                        var exists = context.Solutions.FirstOrDefault(x => x.SolutionId != solution.SolutionId && x.OrganizationId == solution.OrganizationId && x.Type == editFormModel.FormInput.Type && x.SId == editFormModel.FormInput.SId);

                        if (exists == null)
                        {
#if !DEBUG
                            using (TransactionScope trans = new TransactionScope())
                            {
#endif
                            solution.Type           = editFormModel.FormInput.Type;
                            solution.SId            = editFormModel.FormInput.SId;
                            solution.Name           = editFormModel.FormInput.Name;
                            solution.LastModifyTime = DateTime.Now;

                            context.SaveChanges();
#if !DEBUG
                            trans.Complete();
                        }
#endif
                            result.ReturnSuccessMessage(string.Format("{0} {1} {2}", Resources.Resource.Edit, Resources.Resource.Solution, Resources.Resource.Success));
                        }
                        else
                        {
                            result.ReturnFailedMessage(string.Format("{0} {1}", Resources.Resource.SId, Resources.Resource.Exists));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var err = new Error(MethodBase.GetCurrentMethod(), ex);

                Logger.Log(err);

                result.ReturnError(err);
            }

            return(result);
        }
Ejemplo n.º 12
0
        public static RequestResult Delete(List <string> selectedList)
        {
            RequestResult requestResult = new RequestResult();

            try
            {
#if !DEBUG
                using (TransactionScope trans = new TransactionScope())
                {
#endif
                using (CFContext context = new CFContext())
                {
                    foreach (var pId in selectedList)
                    {
                        var person = context.People.Include("Roles").First(x => x.LoginId == pId);
                        context.People.Remove(person);
                    }

                    context.SaveChanges();
                }

#if EquipmentPatrol || EquipmentMaintenance
                using (CFContext context = new CFContext())
                {
                    foreach (var pId in selectedList)
                    {
                        //db.JobUser.RemoveRange(db.JobUser.Where(x => x.UserID == userID).ToList());

                        //db.MJobUser.RemoveRange(db.MJobUser.Where(x => x.UserID == userID).ToList());
                    }

                    db.SaveChanges();
                }
#endif

#if !DEBUG
                trans.Complete();
            }
#endif

                requestResult.ReturnSuccessMessage(string.Format("{0} {1} {2}", Resources.Resource.Delete, Resources.Resource.Person, Resources.Resource.Success));
            }
            catch (Exception e)
            {
                var error = new Error(MethodBase.GetCurrentMethod(), e);
                Logger.Log(error);
                requestResult.ReturnError(error);
                //throw;
            }

            return(requestResult);
        }
Ejemplo n.º 13
0
        public static RequestResult Create(CreateFormModel model)
        {
            RequestResult requestResult = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    var exists = context.Roles.FirstOrDefault(r => r.RoleId == model.FormInput.RoleId);

                    if (exists == null)
                    {
                        var pIds = model.People.Select(p => p.PId);
                        context.Roles.Add(new CF.Models.Role()
                        {
                            RoleId = model.FormInput.RoleId,
                            Name   = model.FormInput.Name,
                            People = context.People.Where(p => pIds.Contains(p.LoginId)).ToList(),
                            WebPermissionWebFunctions = model.FormInput.WebPermissionFunctionList.Select(x => new CF.Models.RolePermissionFunction
                            {
                                RoleId          = model.FormInput.RoleId,
                                WebPermissionId = x.WebPermissionId,
                                WebFunctionId   = x.WebFunctionId
                            }).ToList()
                        });

                        context.SaveChanges();

                        requestResult.ReturnSuccessMessage(string.Format("{0} {1} {2}", Resources.Resource.Create, Resources.Resource.Role, Resources.Resource.Success));
                    }
                    else
                    {
                        requestResult.ReturnFailedMessage(string.Format("{0} {1}", Resources.Resource.RoleId, Resources.Resource.Exists));
                    }
                }
            }
            catch (Exception e)
            {
                var error = new Error(MethodBase.GetCurrentMethod(), e);
                Logger.Log(error);
                requestResult.ReturnError(error);
                //throw;
            }

            return(requestResult);
        }
Ejemplo n.º 14
0
        public static RequestResult ResetPassword(string pId)
        {
            RequestResult requestResult = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    var person = context.People.First(x => x.LoginId == pId);
                    person.Password = person.LoginId;
                    context.SaveChanges();
                    requestResult.ReturnSuccessMessage(string.Format("{0} {1}", Resources.Resource.ResetPassword, Resources.Resource.Success));
                }
            }
            catch (Exception e)
            {
                var error = new Error(MethodBase.GetCurrentMethod(), e);
                Logger.Log(error);
                requestResult.ReturnError(error);
                //throw;
            }

            return(requestResult);
        }
Ejemplo n.º 15
0
        public static object Delete(string roleId)
        {
            RequestResult requestResult = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    context.Roles.Remove(context.Roles.Include("People").First(x => x.RoleId == roleId));
                    context.SaveChanges();
                }

                requestResult.ReturnSuccessMessage(string.Format("{0} {1} {2}", Resources.Resource.Delete, Resources.Resource.Role, Resources.Resource.Success));
            }
            catch (Exception e)
            {
                Error error = new Error(MethodBase.GetCurrentMethod(), e);
                Logger.Log(error);
                requestResult.ReturnError(error);
                //throw;
            }

            return(requestResult);
        }
Ejemplo n.º 16
0
        public static RequestResult Create(CreateFormModel model)
        {
            RequestResult requestResult = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    var exists = context.People.FirstOrDefault(p => p.LoginId == model.FormInput.Id);

                    if (exists == null)
                    {
                        bool exceedsLimit = false;

                        var upStreamOrganizationIds = OrganizationDataAccessor.GetUpStreamOrganizationIds(new Guid(model.OrganizationId), true);

                        PopulationLimit populationLimit = null;

                        foreach (var item in Config.PopulationLimits)
                        {
                            if (upStreamOrganizationIds.Contains(item.OrganizationId))
                            {
                                populationLimit = item;
                                break;
                            }
                        }
                        if (populationLimit != null)
                        {
                            var organization            = OrganizationDataAccessor.GetOrganization(populationLimit.OrganizationId);
                            var downStreamOrganizations = OrganizationDataAccessor.GetDownStreamOrganizations(populationLimit.OrganizationId, true);
                            var people = context.People.Where(p => downStreamOrganizations.Contains(p.OrganizationId)).ToList();
                            if (people.Count + 1 > populationLimit.NumberOfPeople)
                            {
                                exceedsLimit = true;
                                requestResult.ReturnFailedMessage(string.Format(Resources.Resource.ExceedsPopulationLimit, organization.Name, populationLimit.NumberOfPeople));
                            }
                            else
                            {
                                if (model.FormInput.IsMobilePerson && people.Count(x => x.IsMobilePerson) + 1 > populationLimit.NumberOfMobilePeople)
                                {
                                    exceedsLimit = true;
                                    requestResult.ReturnFailedMessage(string.Format(Resources.Resource.ExceedsMobilePopulationLimit, organization.Name, populationLimit.NumberOfMobilePeople));
                                }
                            }
                        }
                        if (!exceedsLimit)
                        {
                            var roles = context.Roles.Where(r => model.FormInput.RoleIdsString.Contains(r.RoleId)).ToList();
                            context.People.Add(new CF.Models.Person()
                            {
                                OrganizationId = new Guid(model.OrganizationId),
                                LoginId        = model.FormInput.Id,
                                Name           = model.FormInput.Name,
                                Password       = model.FormInput.Id,
                                Title          = model.FormInput.Title,
                                Email          = model.FormInput.EMail,
                                IsMobilePerson = model.FormInput.IsMobilePerson,
                                LastModifyTime = DateTime.Now,
                                Roles          = roles
                            });

                            context.SaveChanges();
                            requestResult.ReturnData(model.FormInput.Id, string.Format("{0} {1} {2}", Resources.Resource.Create, Resources.Resource.Person, Resources.Resource.Success));
                        }
                    }
                    else
                    {
                        requestResult.ReturnFailedMessage(string.Format("{0} {1}", Resources.Resource.PId, Resources.Resource.Exists));
                    }
                }
            }
            catch (Exception e)
            {
                var error = new Error(MethodBase.GetCurrentMethod(), e);
                Logger.Log(error);
                requestResult.ReturnError(error);
                //throw;
            }

            return(requestResult);
        }
Ejemplo n.º 17
0
        public static RequestResult Create(CreateFormModel createFormModel)
        {
            RequestResult requestResult = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    var exists = context.Organizations.FirstOrDefault(x => x.ParentId.ToString() == createFormModel.ParentId && x.OId == createFormModel.FormInput.OId);

                    if (exists == null)
                    {
                        //OrganizationId为Guid自动生成,此处先形成organization对象,为了下面获取数据库中自动生成的OrganizationId。
                        //var organization = new CF.Models.Organization()
                        //{
                        //    ParentId = createFormModel.ParentId,
                        //    OId = createFormModel.FormInput.OId,
                        //    Name = createFormModel.FormInput.Name,
                        //};
                        //context.Organizations.Add(organization);

                        var organization = new CF.Models.Organization()
                        {
                            OrganizationId = Guid.NewGuid(),
                            ParentId       = new Guid(createFormModel.ParentId),
                            OId            = createFormModel.FormInput.OId,
                            Name           = createFormModel.FormInput.Name
                        };
                        context.Organizations.Add(organization);


                        if (!string.IsNullOrEmpty(createFormModel.FormInput.Managers))
                        {
                            context.OrganizationManagers.AddRange(createFormModel.FormInput.Managers.Split(',').ToList().Select(om => new OrganizationManager()
                            {
                                OrganizationId = organization.OrganizationId,
                                ManagerId      = om
                            }));
                        }

                        context.EditableOrganizations.AddRange(createFormModel.EditableOrganizations.Where(x => x.CanDelete).Select(x => new EditableOrganization
                        {
                            OrganizationId         = organization.OrganizationId,
                            EditableOrganizationId = x.OrganizationId
                        }).ToList());

                        context.QueryableOrganizations.AddRange(createFormModel.QueryableOrganizations.Select(x => new QueryableOrganization
                        {
                            OrganizationId          = organization.OrganizationId,
                            QueryableOrganizationId = x.OrganizationId
                        }).ToList());

                        context.SaveChanges();

                        requestResult.ReturnData(organization.OrganizationId, string.Format("{0} {1} {2}", Resources.Resource.Create, Resources.Resource.Organization, Resources.Resource.Success));
                    }
                    else
                    {
                        requestResult.ReturnFailedMessage(string.Format("{0} {1}", Resources.Resource.OrganizationId, Resources.Resource.Exists));
                    }
                }
            }
            catch (Exception e)
            {
                var error = new Error(MethodBase.GetCurrentMethod(), e);
                Logger.Log(error);
                requestResult.ReturnError(error);
                //throw;
            }

            return(requestResult);
        }
Ejemplo n.º 18
0
        public static RequestResult Edit(EditFormModel editFormModel)
        {
            RequestResult requestResult = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
#if !DEBUG
                    using (TransactionScope trans = new TransactionScope())
                    {
#endif
                    #region Role
                    var role = context.Roles.Include("People").First(x => x.RoleId == editFormModel.RoleId);

                    role.Name = editFormModel.FormInput.Name;

                    context.SaveChanges();
                    #endregion

                    #region RoleWebPermissionFunction
                    #region Delete
                    context.RolePermissionFunctions.RemoveRange(context.RolePermissionFunctions.Where(x => x.RoleId == role.RoleId).ToList());

                    context.SaveChanges();
                    #endregion

                    #region Insert
                    context.RolePermissionFunctions.AddRange(editFormModel.FormInput.WebPermissionFunctionList.Select(x => new CF.Models.RolePermissionFunction
                    {
                        RoleId          = role.RoleId,
                        WebPermissionId = x.WebPermissionId,
                        WebFunctionId   = x.WebFunctionId
                    }).ToList());

                    context.SaveChanges();
                    #endregion
                    #endregion

                    #region RolePeople
                    #region Delete
                    role.People = new List <CF.Models.Person>();

                    context.SaveChanges();
                    #endregion

                    #region Insert
                    var pIds = editFormModel.People.Select(p => p.PId);
                    role.People = context.People.Where(p => pIds.Contains(p.LoginId)).ToList();

                    context.SaveChanges();
                    #endregion
                    #endregion
#if !DEBUG
                    trans.Complete();
                }
#endif

                    requestResult.ReturnSuccessMessage(string.Format("{0} {1} {2}", Resources.Resource.Edit, Resources.Resource.Role, Resources.Resource.Success));
                }
            }
            catch (Exception e)
            {
                var error = new Error(MethodBase.GetCurrentMethod(), e);
                Logger.Log(error);
                requestResult.ReturnError(error);
                //throw;
            }

            return(requestResult);
        }
Ejemplo n.º 19
0
        public static RequestResult Create(CreateFormModel createFormModel)
        {
            RequestResult result = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    var exists = context.Checkpoints.FirstOrDefault(x => x.OrganizationId == new Guid(createFormModel.OrganizationId) && x.CId == createFormModel.FormInput.CId);

                    if (exists == null)
                    {
                        if (!string.IsNullOrEmpty(createFormModel.FormInput.TagId) && context.Checkpoints.Any(x => x.TagId == createFormModel.FormInput.TagId))
                        {
                            var checkpoint = context.Checkpoints.First(x => x.TagId == createFormModel.FormInput.TagId);

                            var organization = OrganizationDataAccessor.GetOrganization(checkpoint.OrganizationId);

                            result.ReturnFailedMessage(string.Format("{0} {1} {2} {3} {4}", Resources.Resource.TagId, createFormModel.FormInput.TagId, Resources.Resource.Exists, organization.Name, checkpoint.Name));
                        }
                        else
                        {
                            Guid checkpointId = Guid.NewGuid();

                            context.Checkpoints.Add(new CF.Models.Maintenance.Checkpoint()
                            {
                                CheckpointId = checkpointId,
                                OrganizationId = new Guid(createFormModel.OrganizationId),
                                CId = createFormModel.FormInput.CId,
                                Name = createFormModel.FormInput.Name,
                                IsFeelItemDefaultNormal = createFormModel.FormInput.IsFeelItemDefaultNormal,
                                TagId = createFormModel.FormInput.TagId,
                                Remark = createFormModel.FormInput.Remark,
                                CheckItems = createFormModel.CheckItemModels.Select(x => new CF.Models.Maintenance.CheckItem()
                                {
                                    CheckItemId = new Guid(x.CheckItemId),
                                    IsInherit = x.IsInherit,
                                    LowerLimit = x.LowerLimit,
                                    LowerAlertLimit = x.LowerAlertLimit,
                                    UpperAlertLimit = x.UpperAlertLimit,
                                    UpperLimit = x.UpperLimit,
                                    AccumulationBase = x.AccumulationBase,
                                    Unit = x.Unit,
                                    Remark = x.Remark
                                }).ToList(),
                                LastModifyTime = DateTime.Now
                            });

                            context.SaveChanges();

                            result.ReturnData(checkpointId, string.Format("{0} {1} {2}", Resources.Resource.Create, Resources.Resource.Checkpoint, Resources.Resource.Success));
                        }
                    }
                    else
                    {
                        result.ReturnFailedMessage(string.Format("{0} {1}", Resources.Resource.CId, Resources.Resource.Exists));
                    }
                }
            }
            catch (Exception ex)
            {
                var err = new Error(MethodBase.GetCurrentMethod(), ex);

                Logger.Log(err);

                result.ReturnError(err);
            }

            return result;
        }
Ejemplo n.º 20
0
        public static RequestResult Edit(EditFormModel model)
        {
            RequestResult requestResult = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    var organization = context.Organizations.First(o => o.OrganizationId.ToString() == model.OrganizationId);
                    var exists       = context.Organizations.FirstOrDefault(o => o.OrganizationId != organization.OrganizationId && o.ParentId == organization.ParentId && o.OId == model.FormInput.OId);
                    if (exists == null)
                    {
                        organization.OId  = model.FormInput.OId;
                        organization.Name = model.FormInput.Name;

                        context.SaveChanges();

                        context.OrganizationManagers.RemoveRange(context.OrganizationManagers.Where(o => o.OrganizationId.ToString() == model.OrganizationId));
                        context.EditableOrganizations.RemoveRange(context.EditableOrganizations.Where(o => o.OrganizationId.ToString() == model.OrganizationId));
                        context.QueryableOrganizations.RemoveRange(context.QueryableOrganizations.Where(o => o.OrganizationId.ToString() == model.OrganizationId));

                        context.SaveChanges();

                        if (!string.IsNullOrEmpty(model.FormInput.Managers))
                        {
                            string organizationId = model.OrganizationId;
                            context.OrganizationManagers.AddRange(model.FormInput.Managers.Split(',').ToList().Select(o => new OrganizationManager()
                            {
                                OrganizationId = new Guid(organizationId),
                                ManagerId      = o
                            }));
                        }

                        context.EditableOrganizations.AddRange(model.EditableOrganizations.Where(e => e.CanDelete).Select(e => new EditableOrganization
                        {
                            OrganizationId         = new Guid(model.OrganizationId),
                            EditableOrganizationId = e.OrganizationId
                        }));

                        context.QueryableOrganizations.AddRange(model.QueryableOrganizations.Select(q => new QueryableOrganization
                        {
                            OrganizationId          = new Guid(model.OrganizationId),
                            QueryableOrganizationId = q.OrganizationId
                        }));

                        context.SaveChanges();

                        requestResult.ReturnSuccessMessage(string.Format("{0} {1} {2}", Resources.Resource.Edit, Resources.Resource.Organization, Resources.Resource.Success));
                    }
                    else
                    {
                        requestResult.ReturnFailedMessage(string.Format("{0} {1}", Resources.Resource.OrganizationId, Resources.Resource.Exists));
                    }
                }
            }
            catch (Exception e)
            {
                var error = new Error(MethodBase.GetCurrentMethod(), e);
                Logger.Log(error);
                requestResult.ReturnError(error);
                //throw;
            }

            return(requestResult);
        }
Ejemplo n.º 21
0
 public static void SaveChanges()
 {
     dbContext.SaveChanges();
 }
Ejemplo n.º 22
0
        public static RequestResult Edit(EditFormModel editFormModel)
        {
            RequestResult result = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    var checkpoint = context.Checkpoints.Include("CheckItems").First(x => x.CheckpointId == new Guid(editFormModel.CheckpointId));

                    var exists = context.Checkpoints.FirstOrDefault(x => x.CheckpointId != checkpoint.CheckpointId && x.OrganizationId == checkpoint.OrganizationId && x.CId == editFormModel.FormInput.CId);

                    if (exists == null)
                    {
                        if (!string.IsNullOrEmpty(editFormModel.FormInput.TagId) && context.Checkpoints.Any(x => x.CheckpointId != checkpoint.CheckpointId && x.TagId == editFormModel.FormInput.TagId))
                        {
                            var query = context.Checkpoints.First(x => x.CheckpointId != checkpoint.CheckpointId && x.TagId == editFormModel.FormInput.TagId);

                            var organization = OrganizationDataAccessor.GetOrganization(query.OrganizationId);

                            result.ReturnFailedMessage(string.Format("{0} {1} {2} {3} {4}", Resources.Resource.TagId, editFormModel.FormInput.TagId, Resources.Resource.Exists, organization.Name, checkpoint.Name));
                        }
                        else
                        {
            #if !DEBUG
                    using (TransactionScope trans = new TransactionScope())
                    {
            #endif
                            #region ControlPoint
                            checkpoint.CId = editFormModel.FormInput.CId;
                            checkpoint.Name = editFormModel.FormInput.Name;
                            checkpoint.TagId = editFormModel.FormInput.TagId;
                            checkpoint.Remark = editFormModel.FormInput.Remark;
                            checkpoint.IsFeelItemDefaultNormal = editFormModel.FormInput.IsFeelItemDefaultNormal;
                            checkpoint.LastModifyTime = DateTime.Now;

                            context.SaveChanges();
                            #endregion

                            #region CheckItems
                            #region Delete
                            checkpoint.CheckItems = new HashSet<CheckItem>();

                            context.SaveChanges();
                            #endregion

                            #region Insert
                            checkpoint.CheckItems = editFormModel.CheckItemModels.Select(x => new CheckItem()
                            {
                                CheckItemId = new Guid(x.CheckItemId),
                                CIId = x.CIId,
                                Name = x.Name,
                                Type = x.Type,
                                IsInherit = x.IsInherit,
                                IsFeelItem = x.IsFeelItem,
                                IsAccumulation = x.IsAccumulation,
                                LowerLimit = x.LowerLimit,
                                LowerAlertLimit = x.LowerAlertLimit,
                                UpperLimit = x.UpperLimit,
                                UpperAlertLimit = x.UpperAlertLimit,
                                Unit = x.Unit,
                                Remark = x.Remark,
                                AccumulationBase = x.AccumulationBase,
                                LastModifyTime = DateTime.Now
                            }).ToList();

                            context.SaveChanges();
                            #endregion
                            #endregion
            #if !DEBUG
                        trans.Complete();
                    }
            #endif
                            result.ReturnSuccessMessage(string.Format("{0} {1} {2}", Resources.Resource.Edit, Resources.Resource.Checkpoint, Resources.Resource.Success));
                        }
                    }
                    else
                    {
                        result.ReturnFailedMessage(string.Format("{0} {1}", Resources.Resource.Checkpoint, Resources.Resource.Exists));
                    }
                }
            }
            catch (Exception ex)
            {
                var err = new Error(MethodBase.GetCurrentMethod(), ex);

                Logger.Log(err);

                result.ReturnError(err);
            }

            return result;
        }
Ejemplo n.º 23
0
        public static RequestResult Edit(EditFormModel editFormModel)
        {
            RequestResult requestResult = new RequestResult();

            try
            {
                using (CFContext context = new CFContext())
                {
                    var person = context.People.Include("Roles").First(x => x.LoginId == editFormModel.PId);

                    bool exceedsLimit = false;

                    if (editFormModel.FormInput.IsMobilePerson)
                    {
                        var upStreamOrganizationIds = OrganizationDataAccessor.GetUpStreamOrganizationIds(person.OrganizationId, true);

                        PopulationLimit populationLimit = null;

                        foreach (var item in Config.PopulationLimits)
                        {
                            if (upStreamOrganizationIds.Contains(item.OrganizationId))
                            {
                                populationLimit = item;

                                break;
                            }
                        }

                        if (populationLimit != null)
                        {
                            var organization = OrganizationDataAccessor.GetOrganization(populationLimit.OrganizationId);

                            var downStreamOrganizations = OrganizationDataAccessor.GetDownStreamOrganizations(populationLimit.OrganizationId, true);

                            var mobilePeople = context.People.Where(x => x.LoginId != person.LoginId && x.IsMobilePerson && downStreamOrganizations.Contains(x.OrganizationId)).ToList();

                            if (mobilePeople.Count + 1 > populationLimit.NumberOfMobilePeople)
                            {
                                exceedsLimit = true;

                                requestResult.ReturnFailedMessage(string.Format(Resources.Resource.ExceedsMobilePopulationLimit, organization.Name, populationLimit.NumberOfMobilePeople));
                            }
                        }
                    }

                    if (!exceedsLimit)
                    {
#if !DEBUG
                        using (TransactionScope trans = new TransactionScope())
                        {
#endif
                        #region Person
                        person.Name  = editFormModel.FormInput.Name;
                        person.Title = editFormModel.FormInput.Title;
                        person.Email = editFormModel.FormInput.EMail;
                        //person.UID = editFormModel.FormInput.UID;
                        person.IsMobilePerson = editFormModel.FormInput.IsMobilePerson;
                        person.LastModifyTime = DateTime.Now;

                        context.SaveChanges();
                        #endregion

                        #region PersonRoles
                        #region Delete
                        if (person != null)
                        {
                            person.Roles = new List <CF.Models.Role>();
                            context.SaveChanges();
                        }

                        #endregion

                        #region Insert
                        foreach (var roleId in editFormModel.FormInput.RoleIds)
                        {
                            var role = context.Roles.First(r => r.RoleId == roleId);
                            person.Roles.Add(role);
                        }
                        context.SaveChanges();
                        #endregion
                        #endregion
#if !DEBUG
                        trans.Complete();
                    }
#endif
                        requestResult.ReturnSuccessMessage(string.Format("{0} {1} {2}", Resources.Resource.Edit, Resources.Resource.Person, Resources.Resource.Success));
                    }
                }
            }
            catch (Exception e)
            {
                var error = new Error(MethodBase.GetCurrentMethod(), e);
                Logger.Log(error);
                requestResult.ReturnError(error);
                //throw;
            }

            return(requestResult);
        }
Ejemplo n.º 24
0
        public static RequestResult Edit(EditFormModel editFormModel)
        {
            RequestResult requestResult = new RequestResult();

            try
            {
                if (editFormModel.FormInput.MaterialType == Define.New)
                {
                    requestResult.ReturnFailedMessage(string.Format("{0} {1}", Resources.Resource.Unsupported, Resources.Resource.MaterialType));
                }
                else
                {
                    using (CFContext context = new CFContext())
                    {
                        var material = context.Materials.First(x => x.MaterialId == new Guid(editFormModel.MaterialId));

                        var exists = context.Materials.FirstOrDefault(x => x.MaterialId != material.MaterialId && x.OrganizationId == material.OrganizationId && x.MaterialType == editFormModel.FormInput.MaterialType && x.MId == editFormModel.FormInput.MId);

                        if (exists == null)
                        {
#if !DEBUG
                            using (TransactionScope trans = new TransactionScope())
                            {
#endif
                            #region Materials
                            material.MaterialType = editFormModel.FormInput.MaterialType;
                            material.MId          = editFormModel.FormInput.MId;
                            material.Name         = editFormModel.FormInput.MaterialName;
                            //material.Quantity = Model.FormInput.Quantity.HasValue ? Model.FormInput.Quantity.Value : 0;

                            context.SaveChanges();
                            #endregion

                            #region MaterialSpecificationOptionValue
                            #region Delete
                            context.MaterialSpecificationOptions.RemoveRange(context.MaterialSpecificationOptions.Where(x => x.MaterialId == new Guid(editFormModel.MaterialId)).ToList());

                            context.SaveChanges();
                            #endregion

                            #region Insert
                            context.MaterialSpecificationOptions.AddRange(editFormModel.MaterialSpecificationModels.Select(x => new CF.Models.Maintenance.MaterialSpecificationOption
                            {
                                MaterialId       = new Guid(editFormModel.MaterialId),
                                MSpecificationId = new Guid(x.MaterialSpecificationId),
                                MSOptionId       = new Guid(x.MaterialSpecificationOptionId),
                                Value            = x.Value,
                                Seq = x.Seq
                            }).ToList());

                            context.SaveChanges();
                            #endregion
                            #endregion

                            requestResult.ReturnSuccessMessage(string.Format("{0} {1} {2}", Resources.Resource.Edit, Resources.Resource.Material, Resources.Resource.Success));
#if !DEBUG
                            trans.Complete();
                        }
#endif
                        }
                        else
                        {
                            requestResult.ReturnFailedMessage(string.Format("{0} {1}", Resources.Resource.MId, Resources.Resource.Exists));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                var error = new Error(MethodBase.GetCurrentMethod(), e);

                Logger.Log(error);

                requestResult.ReturnError(error);
            }

            return(requestResult);
        }
Ejemplo n.º 25
0
        public static object Edit(EditFormModel editFormModel)
        {
            RequestResult result = new RequestResult();

            try
            {
                if (editFormModel.FormInput.EquipmentType == Define.New)
                {
                    result.ReturnFailedMessage(string.Format("{0} {1}", Resources.Resource.Unsupported, Resources.Resource.EquipmentType));
                }
                else
                {
                    using (CFContext context = new CFContext())
                    {
                        var spec = context.ESpecifications.First(x => x.ESpecificationId == new Guid(editFormModel.EquipmentSpecificationId));

                        var exists = context.ESpecifications.FirstOrDefault(x => x.ESpecificationId != spec.ESpecificationId && x.OrganizationId == spec.OrganizationId && x.EquipmentType == editFormModel.FormInput.EquipmentType && x.Name == editFormModel.FormInput.Name);

                        if (exists == null)
                        {
#if !DEBUG
                            using (TransactionScope trans = new TransactionScope())
                            {
#endif
                            #region EquipmentSpecification
                            spec.EquipmentType = editFormModel.FormInput.EquipmentType;
                            spec.Name          = editFormModel.FormInput.Name;

                            context.SaveChanges();
                            #endregion

                            #region EquipmentSpecificationOption
                            #region Delete
                            context.EquipmentSpecificationOptions.RemoveRange(context.EquipmentSpecificationOptions.Where(x => x.ESpecificationId == new Guid(editFormModel.EquipmentSpecificationId)).ToList());

                            context.SaveChanges();
                            #endregion

                            #region Insert
                            context.ESOptions.AddRange(editFormModel.FormInput.EquipmentSpecificationOptionModels.Select(x => new CF.Models.Maintenance.ESOption
                            {
                                ESOptionId       = !string.IsNullOrEmpty(x.EquipmentSpecificationOptionId) ? new Guid(x.EquipmentSpecificationOptionId) : Guid.NewGuid(),
                                ESpecificationId = spec.ESpecificationId,
                                Name             = x.Name,
                                Seq = x.Seq
                            }).ToList());

                            context.SaveChanges();
                            #endregion
                            #endregion

                            #region EquipmentSpecificationOptionValue
                            var optionList = editFormModel.FormInput.EquipmentSpecificationOptionModels.Where(x => !string.IsNullOrEmpty(x.EquipmentSpecificationOptionId)).Select(x => x.EquipmentSpecificationOptionId).ToList();

                            var specValueList = context.EquipmentSpecificationOptions.Where(x => x.ESpecificationId == spec.ESpecificationId && !optionList.Contains(x.ESOptionId.ToString())).ToList();

                            foreach (var specValue in specValueList)
                            {
                                specValue.ESOptionId = Guid.Empty;
                            }

                            context.SaveChanges();
                            #endregion
#if !DEBUG
                            trans.Complete();
                        }
#endif
                            result.ReturnSuccessMessage(string.Format("{0} {1} {2}", Resources.Resource.Edit, Resources.Resource.EquipmentSpecification, Resources.Resource.Success));
                        }
                        else
                        {
                            result.ReturnFailedMessage(string.Format("{0} {1}", Resources.Resource.EquipmentSpecificationName, Resources.Resource.Exists));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var err = new Error(MethodBase.GetCurrentMethod(), ex);

                Logger.Log(err);

                result.ReturnError(err);
            }

            return(result);
        }
Ejemplo n.º 26
0
        public static RequestResult Create(CreateFormModel createFormModel)
        {
            RequestResult requestResult = new RequestResult();

            try
            {
                if (createFormModel.FormInput.MaterialType == Define.New)
                {
                    requestResult.ReturnFailedMessage(string.Format("{0} {1}", Resources.Resource.Unsupported, Resources.Resource.MaterialType));
                }
                else
                {
                    using (CFContext context = new CFContext())
                    {
                        var exists = context.Materials.FirstOrDefault(x => x.OrganizationId == new Guid(createFormModel.OrganizationId) && x.MaterialType == createFormModel.FormInput.MaterialType && x.MId == createFormModel.FormInput.MId);

                        if (exists == null)
                        {
                            Guid materialId = Guid.NewGuid();

                            context.Materials.Add(new CF.Models.Maintenance.Material()
                            {
                                MaterialId     = materialId,
                                OrganizationId = new Guid(createFormModel.OrganizationId),
                                MaterialType   = createFormModel.FormInput.MaterialType,
                                MId            = createFormModel.FormInput.MId,
                                Name           = createFormModel.FormInput.MaterialName,
                                Quantity       = createFormModel.FormInput.Quantity ?? 0
                            });

                            context.MaterialSpecificationOptions.AddRange(createFormModel.MaterialSpecificationModels.Select(x => new CF.Models.Maintenance.MaterialSpecificationOption
                            {
                                MaterialId       = materialId,
                                MSpecificationId = new Guid(x.MaterialSpecificationId),
                                MSOptionId       = new Guid(x.MaterialSpecificationOptionId),
                                Value            = x.Value,
                                Seq = x.Seq
                            }).ToList());

                            context.SaveChanges();

                            requestResult.ReturnData(materialId, string.Format("{0} {1} {2}", Resources.Resource.Create, Resources.Resource.Material, Resources.Resource.Success));
                        }
                        else
                        {
                            requestResult.ReturnFailedMessage(string.Format("{0} {1}", Resources.Resource.MId, Resources.Resource.Exists));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                var error = new Error(MethodBase.GetCurrentMethod(), e);

                Logger.Log(error);

                requestResult.ReturnError(error);
            }

            return(requestResult);
        }
Ejemplo n.º 27
0
        public static RequestResult Edit(EditFormModel editFormModel)
        {
            RequestResult result = new RequestResult();

            try
            {
                if (editFormModel.FormInput.Type == Define.Other || editFormModel.FormInput.Type == Define.New)
                {
                    result.ReturnFailedMessage(string.Format("{0} {1}", Resources.Resource.Unsupported, Resources.Resource.AbnormalReasonType));
                }
                else
                {
                    using (CFContext context = new CFContext())
                    {
                        var abnormalReason = context.AbnormalReasons.Include("Soutions").First(x => x.AbnormalReasonId == new Guid(editFormModel.AbnormalReasonId));

                        var exists = context.AbnormalReasons.FirstOrDefault(x => x.AbnormalReasonId != abnormalReason.AbnormalReasonId && x.OrganizationId == abnormalReason.OrganizationId && x.Type == editFormModel.FormInput.Type && x.ARId == editFormModel.FormInput.ARId);

                        if (exists == null)
                        {
#if !DEBUG
                            using (TransactionScope trans = new TransactionScope())
                            {
#endif
                            #region AbnormalReason
                            abnormalReason.Type           = editFormModel.FormInput.Type;
                            abnormalReason.ARId           = editFormModel.FormInput.ARId;
                            abnormalReason.Name           = editFormModel.FormInput.Name;
                            abnormalReason.LastModifyTime = DateTime.Now;

                            context.SaveChanges();
                            #endregion

                            #region AbnormalReasonHandlingMethod
                            #region Delete
                            abnormalReason.Solutions = new HashSet <CF.Models.Maintenance.Solution>();
                            context.SaveChanges();
                            #endregion

                            #region Insert
                            abnormalReason.Solutions = editFormModel.SolutionModels.Select(x => new CF.Models.Maintenance.Solution()
                            {
                                SolutionId     = new Guid(x.SolutionId),
                                SId            = x.SId,
                                Name           = x.Name,
                                Type           = x.Type,
                                OrganizationId = new Guid(editFormModel.OrganizationId)
                            }).ToList();
                            context.SaveChanges();
                            #endregion
                            #endregion
#if !DEBUG
                            trans.Complete();
                        }
#endif
                            result.ReturnSuccessMessage(string.Format("{0} {1} {2}", Resources.Resource.Edit, Resources.Resource.AbnormalReason, Resources.Resource.Success));
                        }
                        else
                        {
                            result.ReturnFailedMessage(string.Format("{0} {1}", Resources.Resource.ARId, Resources.Resource.Exists));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                var err = new Error(MethodBase.GetCurrentMethod(), ex);

                Logger.Log(err);

                result.ReturnError(err);
            }

            return(result);
        }