Exemple #1
0
        public TypeDto EditType(TypeDto TypeDto, int userId, int tenantId)
        {
            var TypeObj = _TypeService.Query(x => x.TypeId == TypeDto.TypeId && x.TenantId == tenantId).Select().FirstOrDefault();

            if (TypeObj == null)
            {
                throw new NotFoundException(ErrorCodes.ProductNotFound);
            }
            ValidateType(TypeDto, tenantId);
            foreach (var TypeName in TypeDto.TitleDictionary)
            {
                var TypeTranslation = TypeObj.TypeTranslations.FirstOrDefault(x => x.Language.ToLower() == TypeName.Key.ToLower() &&
                                                                              x.TypeId == TypeDto.TypeId);
                if (TypeTranslation == null)
                {
                    TypeObj.TypeTranslations.Add(new TypeTranslation
                    {
                        Title    = TypeName.Value,
                        Language = TypeName.Key
                    });
                }
                else
                {
                    TypeTranslation.Title = TypeName.Value;
                }
            }

            TypeObj.LastModificationTime = Strings.CurrentDateTime;
            TypeObj.LastModifierUserId   = userId;
            TypeObj.IsDeleted            = TypeDto.IsDeleted;
            _TypeService.Update(TypeObj);
            SaveChanges();
            return(TypeDto);
        }
Exemple #2
0
        public TypeDto CreateType(TypeDto TypeDto, int userId, int tenantId)
        {
            if (GetType(TypeDto.TypeId, tenantId) != null)
            {
                return(EditType(TypeDto, userId, tenantId));
            }
            ValidateType(TypeDto, tenantId);
            var TypeObj = Mapper.Map <Type>(TypeDto);

            foreach (var TypeName in TypeDto.TitleDictionary)
            {
                TypeObj.TypeTranslations.Add(new TypeTranslation
                {
                    Title    = TypeName.Value,
                    Language = TypeName.Key,
                });
            }

            TypeObj.CreationTime  = Strings.CurrentDateTime;
            TypeObj.CreatorUserId = userId;
            TypeObj.TenantId      = tenantId;
            _typeTranslationService.InsertRange(TypeObj.TypeTranslations);
            _TypeService.Insert(TypeObj);
            SaveChanges();
            return(TypeDto);
        }
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="distance">Completed distance.</param>
 /// <param name="duration">Duration of the training.</param>
 /// <param name="trainingEffect">Training effect of the training.</param>
 /// <param name="type">Type of the training.</param>
 public TrainingDto(double distance, TimeSpan duration, double trainingEffect, TypeDto type)
 {
     Distance       = distance;
     Duration       = duration;
     TrainingEffect = trainingEffect;
     Type           = type;
 }
        public bool Save(TypeDto typeDto)
        {
            Type type = new Type
            {
                Id          = typeDto.Id,
                Name        = typeDto.Name,
                Description = typeDto.Description
            };

            try
            {
                using (UnitOfWork unitOfWork = new UnitOfWork())
                {
                    if (typeDto.Id == 0)
                    {
                        unitOfWork.TypeRepository.Insert(type);
                    }
                    else
                    {
                        unitOfWork.TypeRepository.Update(type);
                    }
                    unitOfWork.Save();
                }
                return(true);
            }
            catch
            {
                Console.WriteLine(type);
                return(false);
            }
        }
Exemple #5
0
        public async Task <IActionResult> Edit(int id, [FromBody] TypeDto typeDto)
        {
            if (typeDto == null)
            {
                return(BadRequest("You send a empty country"));
            }

            var typeInDb = _typeService.Exist(id).FirstOrDefault();

            if (typeInDb == null)
            {
                return(BadRequest("Type doesn't exist!"));
            }

            var errorMsg = _typeService.CheckSameName(typeDto.Name);

            if (errorMsg != null)
            {
                return(BadRequest(errorMsg));
            }

            var newType = _typeService.Edit(typeInDb, typeDto);

            var saved = await _typeService.SaveEf();

            if (!saved)
            {
                return(BadRequest());
            }

            return(Ok(_typeService.Exist(newType.Id).ProjectTo <TagDto>(_mapper.ConfigurationProvider).FirstOrDefault()));
        }
Exemple #6
0
        public IActionResult GetType(int id)
        {
            var types      = _dataService.GetTypeTitles(id);
            var singleType = _dataService.GetType(id);

            if (singleType == null)
            {
                return(NotFound());
            }

            TypeDto typeDto = new TypeDto();

            typeDto.Id   = singleType.Id;
            typeDto.Name = singleType.TypeName;
            typeDto.Url  = "http://localhost:5001/api/title" + singleType.Id;

            IList <TypeTitlesDto> typeTitles = types.Select(x => new TypeTitlesDto
            {
                TypeId    = x.TypeId,
                TitleName = x.PrimaryTitle,
                TitleUrl  = "http://localhost:5001/api/title/" + x.Id
            }).ToList();

            return(Ok(new { typeDto, typeTitles }));
        }
 public ActionResult GetType(int id)
 {
     try
     {
         TypeDto Type = new TypeDto();
         using (MABRUKLISTEntities dbcontext = new MABRUKLISTEntities())
         {
             var type = dbcontext.mblist_type.Find(id);
             if (type != null)
             {
                 Type.id   = type.type_key;
                 Type.Type = type.type_name;
                 return(PartialView("AddType", Type));
             }
             else
             {
                 return(Json(new { key = false, value = "Type not Found its Deleted from data base!!" }, JsonRequestBehavior.AllowGet));
             }
         }
     }
     catch (Exception)
     {
         return(Json(new { key = false, value = "Unable to edit the type" }, JsonRequestBehavior.AllowGet));
     }
 }
Exemple #8
0
        public ActionResult Edit(TypeViewModel typeVM)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (TypeServiceReference.TypeClient service = new TypeServiceReference.TypeClient())
                    {
                        TypeDto typeDto = new TypeDto
                        {
                            Id          = typeVM.Id,
                            Name        = typeVM.Name,
                            Description = typeVM.Description
                        };

                        service.PostType(typeDto);
                    }

                    return(RedirectToAction("Index"));
                }

                return(View());
            }
            catch
            {
                return(View());
            }
        }
Exemple #9
0
        public string PostType(TypeDto typeDto)
        {
            if (!_context.Save(typeDto))
            {
                return("Type is not inserted.");
            }

            return("Type was inserted.");
        }
Exemple #10
0
        public string PutType(TypeDto typeDto)
        {
            if (!_context.Save(typeDto))
            {
                return("Type is not updated.");
            }

            return("Type is updated.");
        }
Exemple #11
0
 public IActionResult Delete([FromBody] TypeDto Type)
 {
     try
     {
         service.Delete(Type);
         return(NoContent());
     }
     catch (Exception)
     {
         return(NotFound());
     }
 }
Exemple #12
0
 public ActionResult Put(int id, [FromBody]  TypeDto dto)
 {
     try
     {
         _editType.Execute(dto);
         return(NoContent());
     }
     catch (Exception)
     {
         return(StatusCode(500, "An error has occured."));
     }
 }
        //insertion
        public ActionResult AddOrUpdateType(TypeDto dto)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    using (MABRUKLISTEntities dbcontext = new MABRUKLISTEntities())
                    {
                        if (dto.id == 0)
                        {
                            var data = dbcontext.mblist_type.Where(x => x.type_name == dto.Type).FirstOrDefault();
                            if (data != null)
                            {
                                return(Json(new { key = false, value = "Type already exist" }, JsonRequestBehavior.AllowGet));
                            }
                            else
                            {
                                mblist_type type = new mblist_type()
                                {
                                    type_name = dto.Type
                                };

                                dbcontext.mblist_type.Add(type);
                                dbcontext.SaveChanges();
                                return(Json(new { key = true, value = "Type added successfully" }, JsonRequestBehavior.AllowGet));
                            }
                        }
                        else
                        {
                            var data = dbcontext.mblist_type.Find(dto.id);
                            if (data != null)
                            {
                                data.type_name = dto.Type;
                                dbcontext.SaveChanges();
                                return(Json(new { key = true, value = "Type Updated Successfully" }, JsonRequestBehavior.AllowGet));
                            }
                            else
                            {
                                return(Json(new { key = false, value = "Type is not found" }, JsonRequestBehavior.AllowGet));
                            }
                        }
                    };
                }
                else
                {
                    return(Json(new { key = false, value = "Please enter correct data" }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception)
            {
                return(Json(new { key = false, value = "Unable to save the Type" }, JsonRequestBehavior.AllowGet));
            }
        }
Exemple #14
0
 public void Execute(TypeDto request)
 {
     if (Context.UserTypes.Any(m => m.Type == request.Name))
     {
         throw new EntityAlreadyExists();
     }
     Context.UserTypes.Add(new Domen.UserType
     {
         Type = request.Name
     });
     Context.SaveChanges();
 }
Exemple #15
0
 public PlaneType MapType(TypeDto value)
 {
     return(new PlaneType
     {
         Id = value.ID,
         FleightLength = value.FleightLength,
         MaxHeight = value.MaxHeight,
         MaxMass = value.MaxMass,
         Model = value.Model,
         Places = value.Places,
         Speed = value.Speed
     });
 }
        public int Create(TypeDto Type)
        {
            var validationResult = validator.Validate(Type);

            if (validationResult.IsValid)
            {
                return(unit.Types.Create(mapper.MapType(Type)));
            }
            else
            {
                throw new ValidationException(validationResult.Errors);
            }
        }
        public async Task <IActionResult> Delete([FromBody] TypeDto Type)
        {
            try
            {
                await service.Delete(Type);

                return(NoContent());
            }
            catch (Exception ex)
            {
                return(NotFound(ex));
            }
        }
Exemple #18
0
        public static EmployeeType Map(TypeDto dto)
        {
            if (dto == null)
            {
                return(null);
            }

            return(new EmployeeType
            {
                Id = dto.Id,
                HourlyPrice = dto.HourlyPrice,
                Title = dto.Title
            });
        }
Exemple #19
0
 public static TypeViewModel Map(TypeDto dto)
 {
     if (dto == null)
     {
         return(null);
     }
     return(new TypeViewModel
     {
         Id = dto.Id,
         EmployeeId = dto.EmployeeId,
         HourlyPrice = dto.HourlyPrice,
         Title = dto.Title
     });
 }
 public IActionResult Post([FromBody] TypeDto value)
 {
     try
     {
         return(Ok(service.Create(value)));
     }
     catch (ValidationException e)
     {
         return(BadRequest(e.Message));
     }
     catch (Exception ex)
     {
         return(BadRequest(ex));
     }
 }
Exemple #21
0
        private void ValidateType(TypeDto TypeDto, long tenantId)
        {
            foreach (var name in TypeDto.TitleDictionary)
            {
                if (name.Value.Length > 300)
                {
                    throw new ValidationException(ErrorCodes.MenuNameExceedLength);
                }

                if (_typeTranslationService.CheckNameExist(name.Value, name.Key, TypeDto.TypeId, tenantId))
                {
                    throw new ValidationException(ErrorCodes.NameIsExist);
                }
            }
        }
Exemple #22
0
 public ActionResult Post([FromBody] TypeDto dto)
 {
     try
     {
         _addType.Execute(dto);
         return(StatusCode(201));
     }
     catch (EntityAlreadyExists)
     {
         return(NotFound());
     }
     catch (Exception)
     {
         return(StatusCode(500, "An error has occured."));
     }
 }
Exemple #23
0
        public IResult UpdateType(TypeDto typeDto)
        {
            using WordBookContext db = new();
            Type updatedType = db.Types.Where(t => t.TypeId == typeDto.TypeId).SingleOrDefault();

            if (updatedType == null)
            {
                return(new ErrorResult(Messages.TypeNotFound));
            }
            if (updatedType.Name == "General" || updatedType.Name == "Shared")
            {
                return(new ErrorResult(Messages.CanNotUpdateSystemTypes));
            }
            updatedType.Name = typeDto.Name;
            db.SaveChanges();
            return(new SuccessResult(Messages.TypeUpdated));
        }
Exemple #24
0
        public IResult AddType(TypeDto typeDto)
        {
            using WordBookContext db = new();
            if (db.Types.Any(t => t.Name == typeDto.Name))
            {
                return(new ErrorResult(Messages.TypeAlreadyExists));
            }
            Type addedType = new()
            {
                TypeId = 0,
                UserId = typeDto.UserId,
                Name   = typeDto.Name
            };

            db.Types.Add(addedType);
            db.SaveChanges();
            return(new SuccessResult(Messages.TypeAdded));
        }
Exemple #25
0
        private TypeDto GetClassInfo(Type clazz)
        {
            if (_typeDictionary.ContainsKey(clazz))
            {
                return(_typeDictionary[clazz]);
            }

            var returnValue = new TypeDto
            {
                Name = GetTypeName(clazz)
            };

            _typeDictionary[clazz] = returnValue;

            returnValue.Fields = GetFields(clazz);

            return(returnValue);
        }
Exemple #26
0
 public IActionResult Put(int id, [FromBody] TypeDto Type)
 {
     try
     {
         service.Update(Type, id);
         return(Ok());
     }
     catch (NotFoundException)
     {
         return(NotFound());
     }
     catch (ValidationException e)
     {
         return(BadRequest(e.Message));
     }
     catch (Exception)
     {
         return(BadRequest());
     }
 }
Exemple #27
0
        public async Task <IActionResult> New([FromBody] TypeDto typeDto)
        {
            var errorMsg = _typeService.Validate(typeDto);

            if (errorMsg != null)
            {
                return(BadRequest(errorMsg));
            }

            var newType = _typeService.CreateNew(typeDto);

            var saved = await _typeService.SaveEf();

            if (!saved)
            {
                return(BadRequest());
            }

            return(Ok(Mapper.Map <Type, TypeDto>(newType)));
        }
        public TypeDto GetById(int id)
        {
            TypeDto typeDto = new TypeDto();

            using (UnitOfWork unitOfWork = new UnitOfWork())
            {
                Type type = unitOfWork.TypeRepository.GetByID(id);

                if (type != null)
                {
                    typeDto = new TypeDto
                    {
                        Id          = type.Id,
                        Name        = type.Name,
                        Description = type.Description
                    };
                }
            }

            return(typeDto);
        }
Exemple #29
0
        public IResult DeleteType(TypeDto typeDto)
        {
            using WordBookContext db = new();
            Type deletedType = db.Types.Where(t => t.TypeId == typeDto.TypeId).SingleOrDefault();

            if (deletedType == null)
            {
                return(new ErrorResult(Messages.TypeNotFound));
            }
            if (deletedType.Name == "General" || deletedType.Name == "Shared")
            {
                return(new ErrorResult(Messages.CanNotDeleteSystemTypes));
            }
            if (db.Words.Any(w => w.TypeId == typeDto.TypeId))
            {
                return(new ErrorResult(Messages.CanNotDeleteTypeDueToWords));
            }
            db.Types.Remove(deletedType);
            db.SaveChanges();
            return(new SuccessResult(Messages.TypeDeleted));
        }
        public void Update(TypeDto Type, int id)
        {
            var validationResult = validator.Validate(Type);

            if (!validationResult.IsValid)
            {
                throw new ValidationException(validationResult.Errors);
            }
            try
            {
                unit.Types.Update(mapper.MapType(Type), id);
            }
            catch (ArgumentNullException)
            {
                throw new NotFoundException();
            }
            catch (Exception)
            {
                throw;
            }
        }