Exemplo n.º 1
0
        public async Task <Item> CreateItem(NewItemModel newItemModel, ExtendedUser user)
        {
            var imageUploadResponse = await _imageStoreService.UploadImage(user.Id, newItemModel.Image);

            var item = new Item
            {
                SellerId        = user.Id,
                SellerEmail     = user.Email,
                ItemName        = newItemModel.ItemName,
                ItemDescription = newItemModel.ItemDescription,
                Price           = newItemModel.ItemPrice,
                TimeCreated     = DateTime.Now,
                ItemImageUrl    = imageUploadResponse.ImageUrl,
                ImageFileName   = imageUploadResponse.ImageFileName,
                InUserCart      = "",
                Sold            = false,
                InCart          = false
            };

            await _appDbContext.Items.AddAsync(item);

            await _appDbContext.SaveChangesAsync();

            return(item);
        }
Exemplo n.º 2
0
        public ActionResult Create()
        {
            var model = new NewItemModel();

            model.PublishDateTime = DateTime.Now;
            return(View(model));
        }
Exemplo n.º 3
0
        public IHttpActionResult SaveNewItem([FromBody] NewItemModel newItem)
        {
            ItemData data = new ItemData();

            data.SaveNewItem(newItem);

            return(Ok());
        }
Exemplo n.º 4
0
 public ActionResult Create(NewItemModel model, bool continueEditing)
 {
     if (ModelState.IsValid)
     {
         var entity = model.MapTo <NewItem>();
         model.Id = _newsService.InsertNews(entity);
         return(continueEditing ? RedirectToAction("Edit", new { id = model.Id }) : RedirectToAction("List"));
     }
     return(View(model));
 }
Exemplo n.º 5
0
 public ActionResult Edit(NewItemModel model, bool continueEditing)
 {
     if (ModelState.IsValid)
     {
         var entity = _newsService.GetNewsById(model.Id);
         entity = model.MapTo <NewItemModel, NewItem>(entity);
         _newsService.UpdateNews(entity);
         return(continueEditing ? RedirectToAction("Edit", new { id = model.Id }) : RedirectToAction("List"));
     }
     return(View(model));
 }
Exemplo n.º 6
0
        // private string barCode = "";

        public NewItemPage(string barCode)
        {
            InitializeComponent();
            props          = new PropertiesHelper();
            Items          = new ObservableCollection <Item>();
            BindingContext = newItemModel = new NewItemModel();

            Item = new Item
            {
                BarCode     = barCode,
                CheckInUser = props.GetPropertyValue("UserLoggedInUser"),
                Description = ""
            };

            BindingContext = this;
        }
Exemplo n.º 7
0
        public async Task <IActionResult> CreateItem([FromForm] NewItemModel newItemModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            if (!(newItemModel.Image.Length > 0))
            {
                return(BadRequest());
            }

            string userId = User.FindFirstValue("Id");
            var    user   = await _userManager.FindByIdAsync(userId);

            var item = await _itemRepository.CreateItem(newItemModel, user);

            return(Ok(item));
        }
        public IActionResult AddItemToShoppingList([FromBody] NewItemModel model)
        {
            var username   = User?.Identity?.Name;
            var userResult = _userService?.GetUserForUsername(username);

            if (userResult?.Type == ResultType.Success)
            {
                var listResult = _shoppingListService?.GetListForId(model?.ListId ?? -1);
                if (listResult?.Type == ResultType.Success)
                {
                    var list = listResult.ReturnObj;
                    if (list?.UserId != userResult?.ReturnObj?.Id)
                    {
                        return(Unauthorized("The List does not belong to this user"));
                    }

                    var item = new ListItem()
                    {
                        IsChecked      = false,
                        Itemname       = model?.Itemname,
                        ShoppingListId = list.Id
                    };
                    var addResult = _shoppingListService?.AddItemToList(list.Id, item);
                    if (addResult?.Type == ResultType.Success)
                    {
                        return(Ok(new ShoppingListDto(addResult.ReturnObj)));
                    }

                    return(BadRequest(addResult?.Message));
                }

                return(BadRequest(listResult.Message));
            }

            return(BadRequest(userResult?.Message));
        }
Exemplo n.º 9
0
 public NewItemView(Object Parameter)
 {
     InitializeComponent();
     parameter      = Parameter;
     BindingContext = new NewItemModel();
 }
Exemplo n.º 10
0
        public void SaveNewItem(NewItemModel newItem)
        {
            ItemMasterDBModel item = new ItemMasterDBModel
            {
                ItemNameEnglish              = newItem.ItemNameEnglish,
                ItemOtherName                = newItem.ItemOtherName,
                ProducerCompanyId            = newItem.ProducerCompanyId,
                ItemSellingPrice             = newItem.ItemSellingPrice,
                ItemBuyingDiscountPercentage = newItem.ItemBuyingDiscountPercentage,
                ItemBuyingPrice              = newItem.ItemBuyingPrice,
                TaxesPercentageOnBuying      = newItem.TaxesPercentageOnBuying,
                TaxesValueOnBuying           = newItem.TaxesValueOnBuying,
                TaxesPercentageOnSelling     = newItem.TaxesPercentageOnSelling,
                TaxesValueOnSelling          = newItem.TaxesValueOnSelling,
                ItemDescription              = newItem.ItemDescription,
                CreatedDate  = DateTime.Now,
                LastModified = DateTime.Now,
                ItemStatus   = "active"
            };

            using (SqlDataAccess sql = new SqlDataAccess())
            {
                try
                {
                    sql.StartTransaction("GaroshaPrimoData");

                    //save item master data
                    sql.SaveDataInTransaction("dbo.spItemMaster_Insert", item);

                    //get the new item's id
                    item.ItemId = sql.LoadDataInTransaction <int, dynamic>("dbo.spItemMaster_GetItemId",
                                                                           null).FirstOrDefault();

                    if (newItem.ItemCodes.Length > 0)
                    {
                        for (int i = 0; i < newItem.ItemCodes.Length; i++)
                        {
                            ItemCodeDBModel itemCode = new ItemCodeDBModel
                            {
                                ItemId   = item.ItemId,
                                ItemCode = newItem.ItemCodes[i]
                            };

                            sql.SaveDataInTransaction("dbo.spItemCode_Insert", itemCode);
                        }
                    }

                    if (newItem.TherapeuticClassesIds.Length > 0)
                    {
                        for (int x = 0; x < newItem.TherapeuticClassesIds.Length; x++)
                        {
                            ItemTherapeuticClassDBModel itemTherapeuticClass = new ItemTherapeuticClassDBModel
                            {
                                ItemId             = item.ItemId,
                                TherapeuticClassId = newItem.TherapeuticClassesIds[x]
                            };

                            sql.SaveDataInTransaction("dbo.spItemTherapeuticClass_Insert", itemTherapeuticClass);
                        }
                    }

                    if (newItem.IngredientsIds.Length > 0)
                    {
                        for (int z = 0; z < newItem.IngredientsIds.Length; z++)
                        {
                            ItemIngredientDBModel itemIngredient = new ItemIngredientDBModel
                            {
                                ItemId       = item.ItemId,
                                IngredientId = newItem.IngredientsIds[z]
                            };

                            sql.SaveDataInTransaction("dbo.spItemIngredient_Insert", itemIngredient);
                        }
                    }

                    sql.CommitTransaction();
                }
                catch
                {
                    sql.RollBackTransaction();
                    throw;
                }
            }
        }
Exemplo n.º 11
0
 private void InitData()
 {
     Model         = new NewItemModel();
     Model.NewItem = new Types.ItemType();
 }
Exemplo n.º 12
0
        public void RunStarted(object automationObject, Dictionary <string, string> replacementsDictionary, WizardRunKind runKind,
                               object[] customParams)
        {
            string itemName = replacementsDictionary["$safeitemname$"];

            ThreadHelper.ThrowIfNotOnUIThread();

            if (automationObject is DTE dte)
            {
                object activeProjects      = dte.ActiveSolutionProjects;
                Array  activeProjectsArray = (Array)activeProjects;
                if (activeProjectsArray.Length > 0)
                {
                    Project project = (Project)activeProjectsArray.GetValue(0);
                    if (project != null)
                    {
                        IEnumerable <string> validProjectTypes = Enumerable.Empty <string>();
                        string itemType = string.Empty;
                        GetWizardDataFromTemplate();

                        string projectDirectory = Path.GetDirectoryName(project.FullName);
                        ProjectInformationCommandResult projectInformation = _plcncliCommunication.ExecuteCommand(Resources.Command_get_project_information, null,
                                                                                                                  typeof(ProjectInformationCommandResult),
                                                                                                                  Resources.Option_get_project_information_no_include_detection,
                                                                                                                  Resources.Option_get_project_information_project, $"\"{projectDirectory}\"") as ProjectInformationCommandResult;
                        string projecttype = projectInformation.Type;

                        if (projecttype == null || !validProjectTypes.Contains(projecttype))
                        {
                            MessageBox.Show(
                                $"This template is not available for the selected project. The template is available for the project types" +
                                $"{validProjectTypes.Aggregate(string.Empty, (s1, s2) => s1 + $"\n'{s2}'")}\nbut the selected project is of type\n'{projecttype}'.",
                                "Template not available for project type",
                                MessageBoxButton.OK, MessageBoxImage.Error);
                            throw new WizardBackoutException();
                        }

                        NewItemModel      model     = new NewItemModel(_plcncliCommunication, projectDirectory, itemType);
                        NewItemViewModel  viewModel = new NewItemViewModel(model);
                        NewItemDialogView view      = new NewItemDialogView(viewModel);

                        bool?result = view.ShowModal();
                        if (result != null && result == true)
                        {
                            try
                            {
                                if (itemType.Equals(Resources.ItemType_program))
                                {
                                    _plcncliCommunication.ExecuteCommand(Resources.Command_new_program, null, null,
                                                                         Resources.Option_new_program_project, $"\"{projectDirectory}\"",
                                                                         Resources.Option_new_program_name, itemName,
                                                                         Resources.Option_new_program_component, model.SelectedComponent,
                                                                         Resources.Option_new_program_namespace, model.SelectedNamespace);
                                }
                                else if (itemType.Equals(Resources.ItemType_component))
                                {
                                    string command = Resources.Command_new_component;
                                    if (projecttype.Equals(Resources.ProjectType_ACF))
                                    {
                                        command = Resources.Command_new_acfcomponent;
                                    }
                                    _plcncliCommunication.ExecuteCommand(command, null, null,
                                                                         Resources.Option_new_component_project, $"\"{projectDirectory}\"",
                                                                         Resources.Option_new_component_name, itemName,
                                                                         Resources.Option_new_component_namespace, model.SelectedNamespace);
                                }

                                string[] itemFiles = Directory.GetFiles(Path.Combine(projectDirectory, "src"), $"{itemName}.*pp");
                                foreach (string itemFile in itemFiles)
                                {
                                    project.ProjectItems.AddFromFile(itemFile);
                                }

                                _plcncliCommunication.ExecuteCommand(Resources.Command_generate_code, null, null,
                                                                     Resources.Option_generate_code_project, $"\"{projectDirectory}\"");
                            }catch (PlcncliException e)
                            {
                                MessageBox.Show(e.Message, "Error occured", MessageBoxButton.OK, MessageBoxImage.Error);
                                throw new WizardBackoutException();
                            }
                        }


                        void GetWizardDataFromTemplate()
                        {
                            string wizardData = replacementsDictionary["$wizarddata$"];

                            XDocument  document = XDocument.Parse(wizardData);
                            XNamespace nspace   = document.Root.GetDefaultNamespace();

                            validProjectTypes = document.Element(nspace + "Data").Element(nspace + "ValidProjectTypes")
                                                .Descendants(nspace + "Type").Select(e => e.Value);

                            itemType =
                                document.Element(nspace + "Data").Element(nspace + "ItemType").Value;
                        }
                    }
                }
            }
        }