Beispiel #1
0
        public async Task <ActionResult <MessageType> > Put(int id, TypeDTO type)
        {
            MessageType typeDb = (MessageType)type;

            if (typeDb == null)
            {
                return(BadRequest());
            }

            using (MailingServiceDbContext serviceDbContext = new MailingServiceDbContext())
            {
                try
                {
                    var typeDbLast = await serviceDbContext.MessageTypes.FindAsync(id);

                    typeDbLast.MessageTemplate = type.Template;

                    await serviceDbContext.SaveChangesAsync();

                    return(Ok(typeDbLast));
                }
                catch (Exception ex)
                {
                    return(BadRequest(ex.Message));
                }
            }
        }
        public void TypesControllerUpdateTest()
        {
            var topic      = CreateContext();
            var typeId     = Guid.NewGuid();
            var Logic      = CreateLogic();
            var Controller = new TypesController(Logic);

            TypeEntity type = new TypeEntity()
            {
                Id      = typeId,
                Name    = "First Type",
                Topic   = topic,
                TopicId = topic.Id
            };

            Logic.Create(type);

            type.Name = "Updated Type";

            var result        = Controller.Put(typeId, TypeDTO.ToModel(type));
            var createdResult = result as CreatedAtRouteResult;
            var model         = createdResult.Value as TypeDTO;

            Assert.AreEqual("Updated Type", model.Name);
        }
Beispiel #3
0
 public void Update(TypeDTO entity)
 {
     //
     Data_Access.Models.Type type = _mapper.Map <Data_Access.Models.Type>(entity);
     _db.GetTypeRepo.Update(type);
     _db.Save();
 }
Beispiel #4
0
        public void GetAllTypesCaseErrorInDB()
        {
            var types = new List <Type>();

            types.Add(oneType);
            types.Add(anotherType);
            var typeLogicMock = new Mock <ITypeLogic>(MockBehavior.Strict);

            typeLogicMock.Setup(m => m.GetAll()).Throws(
                new DataAccessException("Error: could not get Table's elements"));
            var typeController = new TypeController(typeLogicMock.Object);
            var typeModels     = new List <TypeDTO>();

            foreach (Type type in types)
            {
                TypeDTO tm = new TypeDTO(type);
                typeModels.Add(tm);
            }

            var result   = typeController.Get();
            var okResult = result as ObjectResult;
            var value    = okResult.Value;

            typeLogicMock.VerifyAll();

            Assert.AreEqual(value, "Error: could not get Table's elements");
            Assert.AreEqual(okResult.StatusCode, 500);
        }
Beispiel #5
0
        public List <TypeDTO> getAllType()
        {
            using (SqlConnection conn = new SqlConnection("Data Source=DESKTOP-4V6I868\\SQLEXPRESS2008;Initial Catalog=Assignment5;User ID=sa;Password=Iluvumerijan12"))
            {
                try
                {
                    List <TypeDTO> list = new List <TypeDTO>();

                    conn.Open();
                    string        sql    = "SELECT [TypeId] ,[TypeName] FROM[dbo].[Type]";
                    SqlCommand    cmd    = new SqlCommand(sql, conn);
                    SqlDataReader reader = cmd.ExecuteReader();
                    while (reader.Read())
                    {
                        TypeDTO ty = new TypeDTO();
                        ty.typeId   = Convert.ToInt32(reader["TypeId"]);
                        ty.typeName = Convert.ToString(reader["TypeName"]);
                        list.Add(ty);
                    }
                    return(list);
                }
                catch
                {
                    return(null);
                }
            }
        }
Beispiel #6
0
        public void DoMeasure(MethodInfo mi, object instance, TypeDTO typeDto)
        {
            Console.Write("Start executing algorithm ");
            Console.ForegroundColor = ConsoleColor.Green;
            Console.Write(typeDto.NameAlgorithm);
            Console.ResetColor();
            Console.Write(" from group ");
            Console.ForegroundColor = ConsoleColor.Green;
            Console.Write(typeDto.NameTypeAlgotrithms + "\n");
            Console.ResetColor();
            Stopwatch sw = new Stopwatch();

            sw.Start();
            object results = mi.Invoke(instance, BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public, null, null, CultureInfo.InvariantCulture);

            sw.Stop();
            dynamic convertedResults = Convert.ChangeType(results, typeDto.ReturnedType);

            Console.Write("Results: ");
            foreach (var res in convertedResults)
            {
                Console.Write(res + "; ");
            }
            if (convertedResults.Count == 0)
            {
                Console.Write("No Results");
            }

            Console.Write("\nElapsed time of executing algorithm ");
            Console.ForegroundColor = ConsoleColor.Green;
            Console.Write(" : " + sw.Elapsed + "\n\n");
            Console.ResetColor();
        }
Beispiel #7
0
        public void GetAllTypesCaseNotEmpty()
        {
            var types = new List <Type>();

            types.Add(oneType);
            types.Add(anotherType);
            var typeLogicMock = new Mock <ITypeLogic>(MockBehavior.Strict);

            typeLogicMock.Setup(m => m.GetAll()).Returns(types);
            var typeController = new TypeController(typeLogicMock.Object);
            var typeModels     = new List <TypeDTO>();

            foreach (Type type in types)
            {
                TypeDTO tm = new TypeDTO(type);
                typeModels.Add(tm);
            }

            var result   = typeController.Get();
            var okResult = result as OkObjectResult;
            var value    = okResult.Value as List <TypeDTO>;

            typeLogicMock.VerifyAll();
            for (int i = 0; i < typeModels.Count; i++)
            {
                Assert.AreEqual(value[i], typeModels[i]);
            }
        }
Beispiel #8
0
        public async Task <bool> EditAsync(TypeDTO model)
        {
            var type = _mapper.Map <Type>(model);

            _repository.Edit(type);

            return(await _repository.SaveAsync() > 0 ? true : false);
        }
Beispiel #9
0
 public int Add(TypeDTO type)
 {
     using (System.Data.IDbConnection connection = Connection.GetConnection())
     {
         string sqlExpression = "Type_Add @name";
         return(connection.Query <int>(sqlExpression, type).FirstOrDefault());
     }
 }
Beispiel #10
0
 public void Update(TypeDTO type)
 {
     using (IDbConnection connection = Connection.GetConnection())
     {
         string sqlExpression = "Type_Update";
         connection.Execute(sqlExpression, type, commandType: CommandType.StoredProcedure);
     }
 }
Beispiel #11
0
 public IActionResult Post([FromBody] TypeDTO model)
 {
     try {
         var typeResult = Logic.Create(TypeDTO.ToEntity(model));
         return(CreatedAtRoute("GetTypes", new { id = typeResult.Id }, TypeDTO.ToModel(typeResult)));
     } catch (ArgumentException e) {
         return(BadRequest(e.Message));
     }
 }
 public static MethodSignatureDTO FromMethod(MethodInfo method)
 {
     return(new MethodSignatureDTO()
     {
         DeclaringType = TypeDTO.FromType(method.DeclaringType),
         MethodName = method.Name,
         ParameterTypes = method.GetParameters().Select(t => TypeDTO.FromType(t.ParameterType)).ToArray()
     });
 }
Beispiel #13
0
 public static type TypeToDAL(TypeDTO t)
 {
     return(new type()
     {
         type_id = t.type_id,
         type_name = t.type_name,
         //questions = e.questions.Where(q => q.type_id == tdto.type_id).ToList()
     });
 }
Beispiel #14
0
        public IActionResult Get(Guid id)
        {
            TypeEntity TypeGet = Logic.Get(id);

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

            return(Ok(TypeDTO.ToModel(TypeGet)));
        }
Beispiel #15
0
        public void PostCaseValidType()
        {
            var typeDTO       = new TypeDTO(oneType);
            var typeLogicMock = new Mock <ITypeLogic>(MockBehavior.Strict);

            typeLogicMock.Setup(m => m.Create(It.IsAny <Type>())).Returns(oneType);
            var typeController = new TypeController(typeLogicMock.Object);

            var result   = typeController.Post(typeDTO);
            var okResult = result as OkObjectResult;
            var value    = okResult.Value;

            typeLogicMock.VerifyAll();

            Assert.AreEqual(typeDTO, value);
        }
Beispiel #16
0
        public void GetTypeByIdCaseExist()
        {
            var typeDTO = new TypeDTO(oneType);

            var typeLogicMock = new Mock <ITypeLogic>(MockBehavior.Strict);

            typeLogicMock.Setup(m => m.Get(It.IsAny <Guid>())).Returns(oneType);
            var typeController = new TypeController(typeLogicMock.Object);

            var result   = typeController.Get(oneType.Id);
            var okResult = result as OkObjectResult;
            var value    = okResult.Value as TypeDTO;

            typeLogicMock.VerifyAll();

            Assert.AreEqual(typeDTO, value);
        }
Beispiel #17
0
        public void PostCaseErrorInDB()
        {
            var typeDTO       = new TypeDTO(oneType);
            var typeLogicMock = new Mock <ITypeLogic>(MockBehavior.Strict);

            typeLogicMock.Setup(m => m.Create(It.IsAny <Type>())).Throws(
                new DataAccessException("Error: Could not add entity to DB"));
            var typeController = new TypeController(typeLogicMock.Object);

            var result   = typeController.Post(typeDTO);
            var okResult = result as ObjectResult;
            var value    = okResult.Value;

            typeLogicMock.VerifyAll();

            Assert.AreEqual(value, "Error: Could not add entity to DB");
            Assert.AreEqual(okResult.StatusCode, 500);
        }
Beispiel #18
0
        public void PostCaseInvalidTypeEmptyFields()
        {
            var typeDTO       = new TypeDTO(oneType);
            var typeLogicMock = new Mock <ITypeLogic>(MockBehavior.Strict);

            typeLogicMock.Setup(m => m.Create(It.IsAny <Type>())).Throws(
                new BusinessLogicException("Error: Type had empty fields"));
            var typeController = new TypeController(typeLogicMock.Object);

            var result   = typeController.Post(typeDTO);
            var okResult = result as ObjectResult;
            var value    = okResult.Value;

            typeLogicMock.VerifyAll();

            Assert.AreEqual(value, "Error: Type had empty fields");
            Assert.AreEqual(okResult.StatusCode, 400);
        }
Beispiel #19
0
        public void PostCaseInvalidTypeAlreadyRegistered()
        {
            var typeDTO       = new TypeDTO(oneType);
            var typeLogicMock = new Mock <ITypeLogic>(MockBehavior.Strict);

            typeLogicMock.Setup(m => m.Create(It.IsAny <Type>())).Throws(
                new BusinessLogicException("Error: Type with same name associated to this topic already registered"));
            var typeController = new TypeController(typeLogicMock.Object);

            var result   = typeController.Post(typeDTO);
            var okResult = result as ObjectResult;
            var value    = okResult.Value;

            typeLogicMock.VerifyAll();

            Assert.AreEqual(value, "Error: Type with same name associated to this topic already registered");
            Assert.AreEqual(okResult.StatusCode, 400);
        }
        public void TypeControllerPostTest()
        {
            var topic      = CreateContext();
            var Logic      = CreateLogic();
            var Controller = new TypesController(Logic);
            var Type       = new TypeEntity
            {
                Id      = Guid.NewGuid(),
                Name    = "First Type",
                Topic   = topic,
                TopicId = topic.Id
            };

            var result        = Controller.Post(TypeDTO.ToModel(Type));
            var createdResult = result as CreatedAtRouteResult;
            var model         = createdResult.Value as TypeDTO;

            Assert.AreEqual(Type.Name, model.Name);
        }
Beispiel #21
0
        public ActionResult Detail(int id)
        {
            TypeVM         typeViewModel  = new TypeVM();
            TypeRepository repository     = new TypeRepository();
            DataOperations dataOperations = new DataOperations();

            TypeDTO typeDTO = repository.GetTypeDTOByID(id);

            typeViewModel.ParentID    = typeDTO.ParentID;
            typeViewModel.ParentName  = typeDTO.ParentTypeName;
            typeViewModel.ID          = typeDTO.ID;
            typeViewModel.Name        = typeDTO.Name;
            typeViewModel.Description = typeDTO.Description;
            if (typeDTO != null)
            {
                typeViewModel.RTypeList = dataOperations.GetTypeByParentId(typeDTO.ID);
            }

            return(PartialView(typeViewModel));
        }
Beispiel #22
0
        public List <TypeDTO> removeType(VenueDTO v)
        {
            TypeDTO t = new TypeDTO();

            t = v.types.Last();



            using (var db = new GG.Models.GGModelContainer())
            {
                Venue VenueTbl = new Venue();

                var existingType = (from x in db.Types where x.Id == t.id select x).FirstOrDefault();


                var existingVenue = (from x in db.Venues where x.Id == v.id select x).FirstOrDefault();



                existingVenue.Types.Remove(existingType);


                db.SaveChanges();

                var l = (from x in existingVenue.Types
                         .Select(b => new TypeDTO
                {
                    id = b.Id,
                    typeText = b.Text
                })

                         select x).ToList();


                return(l);
            }
        }
Beispiel #23
0
        public async Task <ActionResult <MessageStatus> > Post(TypeDTO type)
        {
            MessageType typeDb = (MessageType)type;

            if (typeDb == null)
            {
                return(BadRequest());
            }

            using (MailingServiceDbContext serviceDbContext = new MailingServiceDbContext())
            {
                try
                {
                    serviceDbContext.MessageTypes.Add(typeDb);
                    await serviceDbContext.SaveChangesAsync();

                    return(Ok(typeDb));
                }
                catch (Exception ex)
                {
                    return(BadRequest(ex.Message));
                }
            }
        }
Beispiel #24
0
        public TypeDTO GetTypeDTOByID(int typeID)
        {
            TypeDTO typeDTO = new TypeDTO();


            var query = @"select t1.Name as ParentName,t.ID,t.Name ,t.ParentID,t.Description,t.Code from dbo.[tbl_Type] t 
                           left join [tbl_Type] t1 on t.ParentID =t1.ID
                           where  t.Status=1 and
                           t.id=@T_TypeId";


            using (var connection = new SqlConnection(ConnectionStrings.ConnectionString))
            {
                connection.Open();

                using (var command = new SqlCommand(query.ToString(), connection))
                {
                    command.Parameters.AddWithValue("@T_TypeId", typeID);

                    var reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        typeDTO.ParentTypeName = reader.GetStringOrEmpty(0);
                        typeDTO.ID             = reader.GetInt32OrDefaultValue(1);
                        typeDTO.Name           = reader.GetStringOrEmpty(2);
                        typeDTO.ParentID       = reader.GetInt32OrDefaultValue(3);
                        typeDTO.Description    = reader.GetStringOrEmpty(4);
                        typeDTO.Code           = reader.GetStringOrEmpty(5);
                    }
                }
                connection.Close();
            }

            return(typeDTO);
        }
 public IHttpActionResult Update(int id, TypeDTO typeDTO)
 {
     return(CheckForErrors(typeService.Update(id, typeDTO)));
 }
Beispiel #26
0
 public void Add(TypeDTO entity)
 {
     Data_Access.Models.Type type = _mapper.Map <TypeDTO, Data_Access.Models.Type>(entity);
     _db.GetTypeRepo.Add(type);
     _db.Save();
 }
        public void TypeUpdate(TypeDTO typeDTO)
        {
            var updateType = type.GetAll().SingleOrDefault(c => c.Id == typeDTO.Id);

            type.Update((mapper.Map <TypeDTO, DAL.Models.Type>(typeDTO, updateType)));
        }
        public int TypeCreate(TypeDTO typeDTO)
        {
            var createType = type.Create(mapper.Map <DAL.Models.Type>(typeDTO));

            return((int)createType.Id);
        }
        private void ButSave_Click(object sender, EventArgs e)
        {
            if (tBName.Text == "")
            {
                ShowError("Не все обязательные поля заполнены!");
            }
            else
            {
                if (_Product == null)
                {
                    ProductDTO product = new ProductDTO();
                    product.Name       = tBName.Text.ToString();
                    product.PsevdoName = tBPsevdoName.Text.ToString();
                    if (tBNorm.Text != "")
                    {
                        product.Norm = float.Parse(tBNorm.Text);
                    }
                    if (tBSum.Text != "")
                    {
                        product.Sum = float.Parse(tBSum.Text);
                    }
                    if (tBBalance.Text != "")
                    {
                        product.Balance = float.Parse(tBBalance.Text);
                    }
                    if (tBCarbo.Text != "")
                    {
                        product.Carbohydrate = int.Parse(tBCarbo.Text);
                    }
                    if (tBProtein.Text != "")
                    {
                        product.Protein = int.Parse(tBProtein.Text);
                    }
                    if (tBFat.Text != "")
                    {
                        product.Fat = int.Parse(tBFat.Text);
                    }
                    if (tBVitamine.Text != "")
                    {
                        product.Vitamine_C = int.Parse(tBVitamine.Text);
                    }
                    TypeDTO type = MainForm.DB.Types.GetAll().Where(x => x.Name == cBType.SelectedValue.ToString()).First();
                    product.Type   = type;
                    product.TypeId = type.Id;
                    UnitDTO unit = MainForm.DB.Units.GetAll().Where(x => x.Name == cBUnit.SelectedValue.ToString()).First();
                    product.Unit   = unit;
                    product.UnitId = unit.Id;
                    MainForm.DB.Products.Create(product);
                    actions.Add(new ActionDescription("Характеристики продукта: " + product.Name, "Псевдоним: " + product.PsevdoName, "Ед. изм.: " + product.Unit.Name, "Тип: " + product.Type.Name, "Сумма: " + product.Sum.ToString(), "Количество: " + product.Balance.ToString(), "Норма = " + product.Norm.ToString(), "Углеводы: " + product.Carbohydrate.ToString(), "Жиры: " + product.Fat.ToString(), "Белки: " + product.Protein.ToString(), "Витамин С: " + product.Vitamine_C.ToString()));
                    logMessage.Append(product.Name);
                }
                else
                {
                    ProductDTO product = MainForm.DB.Products.Get(_Product.Id);
                    product.Name       = tBName.Text.ToString();
                    product.PsevdoName = tBPsevdoName.Text.ToString();
                    if (tBNorm.Text != "")
                    {
                        product.Norm = float.Parse(tBNorm.Text);
                    }
                    if (tBCarbo.Text != "")
                    {
                        product.Carbohydrate = int.Parse(tBCarbo.Text);
                    }
                    if (tBProtein.Text != "")
                    {
                        product.Protein = int.Parse(tBProtein.Text);
                    }
                    if (tBSum.Text != "")
                    {
                        product.Sum = float.Parse(tBSum.Text);
                    }
                    if (tBBalance.Text != "")
                    {
                        product.Balance = float.Parse(tBBalance.Text);
                    }
                    if (tBFat.Text != "")
                    {
                        product.Fat = int.Parse(tBFat.Text);
                    }
                    if (tBVitamine.Text != "")
                    {
                        product.Vitamine_C = int.Parse(tBVitamine.Text);
                    }
                    TypeDTO type = MainForm.DB.Types.GetAll().Where(x => x.Name == cBType.SelectedValue.ToString()).First();
                    product.Type   = type;
                    product.TypeId = type.Id;
                    UnitDTO unit = MainForm.DB.Units.GetAll().Where(x => x.Name == cBUnit.SelectedValue.ToString()).First();
                    product.Unit   = unit;
                    product.UnitId = unit.Id;

                    MainForm.DB.Products.Update(product);
                    actions.Add(new ActionDescription("Характеристики продукта: " + product.Name, "Псевдоним: " + product.PsevdoName, "Ед. изм.: " + product.Unit.Name, "Тип: " + product.Type.Name, "Cумма: " + product.Sum.ToString(), "Количество: " + product.Balance.ToString(), "Норма = " + product.Norm.ToString(), "Углеводы: " + product.Carbohydrate.ToString(), "Жиры: " + product.Fat.ToString(), "Белки: " + product.Protein.ToString(), "Витамин С: " + product.Vitamine_C.ToString()));
                    logMessage.Append(product.Name);
                }
                MainForm.DB.Save();
                MessageBox.Show("Продукт успешно сохранён");
                LoggingService.AddLog(logMessage.ToString(), actions.ToArray());
                this.Close();
            }
        }
 public IHttpActionResult Post(TypeDTO typeDTO)
 {
     return(CheckForErrors(typeService.Save(typeDTO)));
 }