Exemplo n.º 1
0
        public ServiceResult <object> Save(BusinessParam bp, OrganizationDto dto)
        {
            var methodName = $".{new StackTrace().GetFrame(1).GetMethod().Name}";

            try
            {
                DataLayer.Model.Core.Organization.Organization organization;
                if (dto.EntityId == 0)
                {
                    using (var unitOfWork = new UnitOfWork())
                    {
                        organization = Copier.GetEntity(dto, bp, true);
                        unitOfWork.Organization.Insert(organization);
                        unitOfWork.Organization.Save();
                    }
                }
                else
                {
                    using (var unitOfWork = new UnitOfWork())
                    {
                        organization = Copier.GetEntity(dto, bp, false);
                        unitOfWork.Organization.Update(organization);
                        unitOfWork.Organization.Save();
                    }
                }

                Elastic <OrganizationDto, DataLayer.Model.Core.Organization.Organization> .SaveToElastic(organization,
                                                                                                         ClassDetails[0].Clazz, bp);

                return(new ServiceResult <object>(Copier.GetDto(organization), 1));
            }
            catch (Exception e)
            {
                return(ExceptionUtil.ExceptionHandler(e, ClassDetails[0].Facade + methodName, bp.UserInfo));
            }
        }
Exemplo n.º 2
0
        public string SetAccessKey(OrganizationDto organizationDto, long?parentId, BusinessParam bp)
        {
            var methodName = $".{new StackTrace().GetFrame(1).GetMethod().Name}";

            try
            {
                var tableName = Util.GetSqlServerTableName <DataLayer.Model.Core.Organization.Organization>();
                using (var unitOfWork = new UnitOfWork())
                {
                    var parentOrganization = unitOfWork.Organization.Get(p => p.EntityId == parentId)
                                             .FirstOrDefault();
                    var queryString = parentId == null
                        ? $"SELECT max(AccessKey) FROM {tableName} WHERE ParentId is null AND Deleted=0"
                        : $"SELECT max(AccessKey) FROM {tableName} WHERE ParentId = {parentId} AND Deleted=0";
                    var data = unitOfWork.ComboVal.CreateNativeQuery(queryString, x => new[]
                    {
                        x[0]
                    });
                    if (data.Count > 0)
                    {
                        var ak = data[0][0].ToString();
                        var siblingLastPart = "";
                        if (ak != null)
                        {
                            siblingLastPart = ak.Substring(ak.Length - 3);
                        }
                        else
                        {
                            var query = parentId == null
                                ? $"SELECT AccessKey FROM {tableName} WHERE entityId is null AND Deleted=0"
                                : $"SELECT AccessKey FROM {tableName} WHERE entityId = {parentId} AND Deleted=0";
                            var orgIds = unitOfWork.ComboVal.CreateNativeQuery(query, x => new[]
                            {
                                x[0]
                            });
                            if (orgIds.Count > 0)
                            {
                                siblingLastPart = orgIds[0].ToString();
                            }
                        }

                        var nextKey = NextKey(siblingLastPart);
                        if (parentOrganization?.AccessKey != null)
                        {
                            return(parentOrganization.AccessKey + nextKey);
                        }
                        return(nextKey);
                    }

                    if (parentOrganization?.AccessKey != null)
                    {
                        return(parentOrganization.AccessKey + "AAA");
                    }
                    return("AAA");
                }
            }
            catch (Exception e)
            {
                ExceptionUtil.ExceptionHandler(e, ClassDetails[0].Facade + methodName, bp.UserInfo);
                return("AAA");
            }
        }
Exemplo n.º 3
0
        public ServiceResult <object> GetDtoFromRequest(HttpRequest request)
        {
            var dto = new OrganizationDto();

            if (!string.IsNullOrEmpty(request.Form["EntityId"]))
            {
                dto.EntityId = Convert.ToInt64(request.Form["EntityId"]);
            }
            if (!string.IsNullOrEmpty(request.Form["name"]))
            {
                dto.Name = request.Form["Name"];
            }
            else
            {
                return(new ServiceResult <object>(Enumerator.ErrorCode.ApplicationError,
                                                  "لطفا نام سازمان را وارد نمایید"));
            }
            if (!string.IsNullOrEmpty(request.Form["establishingYear"]))
            {
                dto.EstablishingYear = Convert.ToDouble(request.Form["establishingYear"]);
            }
            if (!string.IsNullOrEmpty(request.Form["order"]))
            {
                dto.Order = request.Form["order"];
            }
            if (!string.IsNullOrEmpty(request.Form["longitude"]))
            {
                dto.Longitude = request.Form["longitude"];
            }
            if (!string.IsNullOrEmpty(request.Form["latitude"]))
            {
                dto.Latitude = request.Form["latitude"];
            }
            if (!string.IsNullOrEmpty(request.Form["area"]))
            {
                dto.Area = request.Form["area"];
            }
            if (!string.IsNullOrEmpty(request.Form["numberOfFloors"]))
            {
                dto.NumberOfFloors = request.Form["numberOfFloors"];
            }
            if (!string.IsNullOrEmpty(request.Form["numberOfRooms"]))
            {
                dto.NumberOfRooms = request.Form["numberOfRooms"];
            }
            if (!string.IsNullOrEmpty(request.Form["yearOfConstruction"]))
            {
                dto.YearOfConstruction = Convert.ToDouble(request.Form["yearOfConstruction"]);
            }
            if (!string.IsNullOrEmpty(request.Form["fax"]))
            {
                dto.Fax = request.Form["fax"];
            }
            if (!string.IsNullOrEmpty(request.Form["mobile"]))
            {
                dto.Mobile = request.Form["mobile"];
            }
            if (!string.IsNullOrEmpty(request.Form["email"]))
            {
                dto.Email = request.Form["email"];
            }
            if (!string.IsNullOrEmpty(request.Form["address"]))
            {
                dto.Address = request.Form["address"];
            }
            if (!string.IsNullOrEmpty(request.Form["smsNumber"]))
            {
                dto.SmsNumber = request.Form["smsNumber"];
            }
            if (!string.IsNullOrEmpty(request.Form["telPhone"]))
            {
                dto.TelPhone = request.Form["telPhone"];
            }
            if (!string.IsNullOrEmpty(request.Form["code"]))
            {
                dto.Code = request.Form["code"];
            }
            if (!string.IsNullOrEmpty(request.Form["description"]))
            {
                dto.Description = request.Form["description"];
            }
            if (!string.IsNullOrEmpty(request.Form["active"]))
            {
                dto.Active = Convert.ToBoolean(request.Form["active"]);
            }
            if (!string.IsNullOrEmpty(request.Form["parent"]))
            {
                dto.Parent = new OrganizationDto {
                    EntityId = Convert.ToInt64(request.Form["parent"])
                }
            }
            ;
            if (!string.IsNullOrEmpty(request.Form["organizationStatus"]))
            {
                dto.OrganizationStatus = new ComboValDto
                {
                    EntityId = Convert.ToInt64(request.Form["organizationStatus"])
                }
            }
            ;
            if (!string.IsNullOrEmpty(request.Form["organizationOwnershipType"]))
            {
                dto.OrganizationOwnershipType = new ComboValDto
                {
                    EntityId = Convert.ToInt64(request.Form["organizationOwnershipType"])
                }
            }
            ;
            if (!string.IsNullOrEmpty(request.Form["organizationRoadType"]))
            {
                dto.OrganizationRoadType = new ComboValDto
                {
                    EntityId = Convert.ToInt64(request.Form["organizationRoadType"])
                }
            }
            ;
            if (!string.IsNullOrEmpty(request.Form["province"]))
            {
                dto.Province = new LocationDto {
                    EntityId = Convert.ToInt64(request.Form["province"])
                }
            }
            ;
            if (!string.IsNullOrEmpty(request.Form["city"]))
            {
                dto.City = new LocationDto {
                    EntityId = Convert.ToInt64(request.Form["city"])
                }
            }
            ;
            if (!string.IsNullOrEmpty(request.Form["organizationType"]))
            {
                dto.OrganizationType = new ComboValDto {
                    EntityId = Convert.ToInt64(request.Form["organizationType"])
                }
            }
            ;
            if (!string.IsNullOrEmpty(request.Form["organizationGrade"]))
            {
                dto.OrganizationGrade = new ComboValDto {
                    EntityId = Convert.ToInt64(request.Form["organizationGrade"])
                }
            }
            ;
            if (!string.IsNullOrEmpty(request.Form["Logo"]))
            {
                dto.Logo = new FileDto {
                    EntityId = Convert.ToInt64(request.Form["Logo"])
                }
            }
            ;
            if (!string.IsNullOrEmpty(request.Form["aboutUs"]))
            {
                dto.AboutUs = request.Form["aboutUs"];
            }
            if (!string.IsNullOrEmpty(request.Form["Ticket"]))
            {
                dto.Ticket = request.Form["Ticket"];
            }
            return(new ServiceResult <object>(dto, 1));
        }