Ejemplo n.º 1
0
        public void AddAsyncTest()
        {
            //Arrange
            var request = new ModifierDto
            {
                Modifier_code = "COD",
                Modifier_desc = "DESC",
                Is_active     = false
            };

            var response = new R6ResponseDto <int>()
            {
                Data = 12
            };

            // Act
            var mockService = _moqSerivceFixture.ModifierService.Value;

            mockService.Setup(m => m.AddAsync(It.IsAny <ModifierDto>())).ReturnsAsync(response).Verifiable();
            var controller   = new ModifierController(mockService.Object);
            var actionResult = controller.AddAsync(request);
            var result       = Assert.IsType <Task <R6ResponseDto <int> > >(actionResult);

            // Assert
            Assert.NotNull(result);
            var expectedData = ((R6.Model.Common.R6ResponseDto <int>)result.Result);

            Assert.Equal(response.Data, expectedData.Data);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Updates the asynchronous.
        /// </summary>
        /// <param name="modifierDto">The modifier dto.</param>
        /// <returns></returns>
        public async Task <R6ResponseDto <bool> > UpdateAsync(ModifierDto modifierDto)
        {
            var serviceResult = await _modifierRepository.UpdateAsync(modifierDto);

            if (string.IsNullOrEmpty(serviceResult.Message))
            {
                return(GetResponse(serviceResult.Response));
            }
            else
            {
                return(GetResponse(serviceResult.Response, ResponseStatus.Failure, new List <ErrorMessage>()
                {
                    new ErrorMessage {
                        Code = ErrorCode.Sql, Message = serviceResult.Message
                    }
                }));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Updates the modifier.
        /// </summary>
        /// <param name="modifierDto">The modifier dto.</param>
        /// <returns></returns>
        public async Task <(bool Response, string Message)> UpdateAsync(ModifierDto modifierDto)
        {
            bool   response = false;
            string message  = string.Empty;

            if (null != modifierDto)
            {
                var existisModifier = await GetByCodeAsync(modifierDto.Modifier_code.Trim());

                if (existisModifier != null && existisModifier.Procedure_Modifier_Id != modifierDto.Modifier_id)
                {
                    message = "The code entered is a duplicate.";
                }
                else
                {
                    var obj_C_PROCEDURE_MODIFIER = await MidUnit.GetRepository <C_PROCEDURE_MODIFIER>()
                                                   .GetByIdAsync(modifierDto.Modifier_id);

                    if (obj_C_PROCEDURE_MODIFIER == null)
                    {
                        message = Enums.ErrorCode.ObjectNotFound.ToString();
                    }
                    else
                    {
                        obj_C_PROCEDURE_MODIFIER.Updated_By   = UserId.ToString();
                        obj_C_PROCEDURE_MODIFIER.Updated_Date = DateTime.Now;

                        obj_C_PROCEDURE_MODIFIER.Proc_Mod_Code = modifierDto.Modifier_code.Trim();
                        obj_C_PROCEDURE_MODIFIER.Proc_Mod_Desc = modifierDto.Modifier_desc.Trim();
                        obj_C_PROCEDURE_MODIFIER.Is_Active     = modifierDto.Is_active;

                        MidUnit.GetRepository <C_PROCEDURE_MODIFIER>().Update(obj_C_PROCEDURE_MODIFIER);
                        response = await MidUnit.CommitAsync();
                    }
                }
            }
            return(response, message);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Adds the modifier.
        /// </summary>
        /// <param name="modifierDto">The modifier dto.</param>
        /// <returns></returns>
        public async Task <(int Id, string Message)> AddAsync(ModifierDto modifierDto)
        {
            int    rowId   = 0;
            string message = string.Empty;

            if (null != modifierDto)
            {
                var existisModifier = await GetByCodeAsync(modifierDto.Modifier_code.Trim());

                if (existisModifier != null)
                {
                    message = "The code entered is a duplicate.";
                }
                else
                {
                    var obj_C_PROCEDURE_MODIFIER = new C_PROCEDURE_MODIFIER();
                    obj_C_PROCEDURE_MODIFIER.Company_Id   = CompanyId;
                    obj_C_PROCEDURE_MODIFIER.Created_By   = UserId.ToString();
                    obj_C_PROCEDURE_MODIFIER.Created_Date = DateTime.Now;
                    obj_C_PROCEDURE_MODIFIER.Updated_By   = UserId.ToString();
                    obj_C_PROCEDURE_MODIFIER.Updated_Date = DateTime.Now;

                    obj_C_PROCEDURE_MODIFIER.Proc_Mod_Code     = modifierDto.Modifier_code.Trim();
                    obj_C_PROCEDURE_MODIFIER.Proc_Mod_Desc     = modifierDto.Modifier_desc.Trim();
                    obj_C_PROCEDURE_MODIFIER.Is_Active         = modifierDto.Is_active;
                    obj_C_PROCEDURE_MODIFIER.avail_chg_capture = false;

                    MidUnit.GetRepository <C_PROCEDURE_MODIFIER>()
                    .Add(obj_C_PROCEDURE_MODIFIER);

                    var saved = await MidUnit.CommitAsync();

                    rowId = saved ? obj_C_PROCEDURE_MODIFIER.Procedure_Modifier_Id : 0;
                }
            }

            return(rowId, message);
        }
Ejemplo n.º 5
0
 public Task <R6ResponseDto <bool> > UpdateAsync(int id, ModifierDto modifierDto)
 {
     modifierDto.Modifier_id = id;
     return(_modifierService.UpdateAsync(modifierDto));
 }
Ejemplo n.º 6
0
 public Task <R6ResponseDto <int> > AddAsync(ModifierDto modifierDto) =>
 _modifierService.AddAsync(modifierDto);
Ejemplo n.º 7
0
        private ModifierGroupDto ModifierGrouptoModifierGroupDto(string key, ModifierGroup mg, MenuDoc menu, bool cancel)
        {
            if (mg.MaximumSelection == 0)
            {
                mg.MaximumSelection = null;
            }

            if (mg.MaximumSelection.HasValue && mg.MinimumSelection.HasValue && mg.MaximumSelection.Value < mg.MinimumSelection.Value)
            {
                mg.MaximumSelection = mg.MinimumSelection;
            }

            var mgDto = new ModifierGroupDto
            {
                ID               = key,
                DisplayOrder     = mg.DisplayOrder,
                IsAutoSel        = mg.IsAutoSel,
                IsForceSel       = mg.IsForceSel,
                IsSingleSel      = mg.IsSingleSel,
                IsCollapsed      = mg.IsCollapsed.HasValue ? mg.IsCollapsed.Value : false,
                Name             = mg.Name,
                IsPromptSel      = mg.IsPromptSel.HasValue ? mg.IsPromptSel.Value : false,
                MaximumSelection = mg.MaximumSelection,
                MinimumSelection = mg.MinimumSelection,
                IncludeQuantity  = mg.IncludeQuantity,
            };

            foreach (var mod in mg.Modifiers.OrderBy(o => o.DisplayOrder))
            {
                var mDto = new ModifierDto
                {
                    Code            = mod.Code,
                    DisplayName     = mod.DisplayName,
                    DisplayOrder    = mod.DisplayOrder,
                    ID              = mod.ID,
                    MaxQty          = mod.MaxQty,
                    MinQty          = mod.MinQty,
                    Name            = mod.Name,
                    Status          = mod.Status,
                    OldState        = mod.Status,
                    PhotoUrl        = mod.PhotoURL,
                    Price           = mod.Price,
                    TaxRate         = mod.TaxRate,
                    LinkedProductID = mod.LinkedProductId,
                    ModifierGroupId = int.Parse(mgDto.ID),
                    ModifierGroup   = mgDto,
                };
                if (!string.IsNullOrEmpty(mod.LinkedProductId))
                {
                    var linkedProduct = menu.Products.Where(p => p.Key == mod.LinkedProductId).FirstOrDefault();
                    if (linkedProduct.Key != null)
                    {
                        mDto.Status   = linkedProduct.Value.Status ?? 0;
                        mDto.OldState = linkedProduct.Value.Status == 3 ? 0 : linkedProduct.Value.Status;
                        if (!cancel)
                        {
                            var linkedModifierGroups = menu.ModifierGroups.Where(group => linkedProduct.Value.ModifierGroups.Contains(group.Key)).OrderBy(o => o.Value.DisplayOrder);
                            foreach (var linkedGroup in linkedModifierGroups)
                            {
                                var currentMdg = ModifierGrouptoModifierGroupDto(linkedGroup.Key, linkedGroup.Value, menu, true);
                                mDto.SubModifiers.Add(currentMdg);
                                currentMdg.ParentModifier = mDto;
                            }
                        }
                    }
                }

                mgDto.ModifiersList.Add(mDto);
            }

            return(mgDto);
        }