public async Task <int> SaveAsync(Entities.Item Item) { return(await Task.Factory.StartNew(() => { return this.Save(Item); })); }
public void AddItem(Entities.Item item) { if (item != null) { items.Add(item); } }
public Fight(ulong userId, string enemyName, IUserMessage message) { tmpUser = User.GetUserAsync(userId).Result; var enemies = StaticBase.Database.GetCollection <Entities.Enemy>("Enemies") .FindSync(x => x.Name.Equals(enemyName)).ToList(); Message = message; if (enemies.Count == 0) { message.DeleteAsync().Wait(); throw new ArgumentException($"**Error**: No Enemy called {enemyName} could be found.\n" + $"Available Enemies are: `{string.Join(", ", StaticBase.Database.GetCollection<Entities.Enemy>("Enemies").FindSync(y => true).ToList().Select(y => y.Name))}`"); } Enemy = enemies.First(); Weapon = StaticBase.Database.GetCollection <Entities.Item>("Items").FindSync(x => x.Id == tmpUser.WeaponId).First(); Health = tmpUser.CalcCurLevel() + Weapon.BaseDefence + 10; for (int i = 0; i < Weapon.Moveset.Count; i++) { int curIndex = i; Program.ReactionHandler.AddHandler(Message, (IEmote)ReactionPoll.EmojiDict[i], x => SkillUsed(x, curIndex), false).Wait(); } Message.ModifyAsync(x => { x.Embed = FightEmbed().Result; x.Content = ""; }); }
public async Task <IHttpActionResult> Add(Entities.Item Item) { Item.Code = 0; // enforce NEW item var bll = new BLL.Items(); return(Ok <int>(await bll.SaveAsync(Item))); }
public ItemHelper(Entities.Item item) { Id = item.Id; Nome = item.Nome; Descricao = item.Descricao; UrlFoto = item.Foto; Valor = item.Valor; }
/// <summary> /// Lấy thông tin vùng theo xã phường. /// </summary> /// <param name="wardId"></param> /// <returns></returns> public JsonResult GetRegionByWard(int wardId) { RegionService regionService = new RegionService(); var result = regionService.GetRegionByWard(wardId); if (result == null) { result = new Entities.Item(); } return(Json(result)); }
static void InsertSingleItemEntityLite(int i) { using (var ds = new NorthwindDataService()) { var item = new Entities.Item { Field1 = "Field 1." + i.ToString(), Field2 = "Field 2." + i.ToString(), Field3 = "Field 3." + i.ToString(), Field4 = "Field 4." + i.ToString() }; ds.ItemRepository.Insert(item); } }
/// <summary> /// Получение элемента списка по коду /// </summary> /// <param name="id">ID элемента</param> /// <returns>элемент</returns> public object GetObjectById(string id) { var item = new Entities.Item { Id = id, Value = List.Find(x => x.Id == id).Name }; if (item.Id == "4") { item.Value += " " + GetNumberPeriod(); } return(item); }
public async Task <Response> Handle(CadastrarItemRequest request, CancellationToken cancellationToken) { if (request == null) { AddNotification("Resquest", "Preencha as informações do Item"); return(new Response(this)); } var empresa = _repositoryEmpresa.ObterPorId(request.FkEmpresa.Value); string urlFoto = ""; if (empresa == null) { AddNotification("Empresa", "Empresa inválida"); return(new Response(this)); } //if (request.Foto != null) //{ // urlFoto = "Imagens/" + _imagem.UploadImage(request.Foto).Result; //} Entities.Item item = new Entities.Item(request.Nome, request.Descricao, request.Valor, urlFoto, request.Tipo, empresa); if (IsInvalid()) { return(new Response(this)); } AddNotifications(item); item = _repositoryItem.Adicionar(item); empresa.AdicionarItem(item); _repositoryEmpresa.Editar(empresa); try { _unitOfWork.SaveChanges(); } catch (Exception ex) { this.AddNotification("Adicionar Item", "Erro ao persistir dados: " + ex.Message); } var result = new { Nome = item.Nome, Descricao = item.Descricao, Valor = item.Valor, UrlFoto = item.Foto, Empresa = item.Empresa.Fantasia }; var response = new Response(this, result); return(await Task.FromResult(response)); }
//static void ShowAllEmployeesThatSoldSpecifiedProducts() //{ // var query = ds.EmployeeRepository.ThatSoldAllSpecifiedProductsQuery(Enumerable.Range(1, 6)) // .Fields(EmployeeFields.EmployeeId, EmployeeFields.FirstName, EmployeeFields.LastName) // .OrderBy(EmployeeFields.FirstName, EmployeeFields.LastName); // var any = query.Any(); // foreach (var e in query.ToEnumerable()) // { // Console.WriteLine("{0}: {1} {2}", e.EmployeeId, e.FirstName, e.LastName); // } //} static void InsertMultipleItems(int itemCount) { ds.BeginTransaction(); for (int i = 1; i < itemCount; i++) { var item = new Entities.Item { Field1 = "Field 1." + i.ToString(), Field2 = "Field 2." + i.ToString(), Field3 = "Field 3." + i.ToString(), Field4 = "Field 4." + i.ToString() }; ds.ItemRepository.Insert(item); } ds.Commit(); }
public int CheckRolePost(ref Entities.Item e) { int userId = 0; int.TryParse(CookieHelper.Get(AdminConfigs.COOKIES_USER_ID), out userId); if (userId == 0) { return((int)Errors.NOT_LOGIN); } UserInRolesService uirService = new UserInRolesService(); var result = uirService.GetRoleAllowPost(userId); if (result == null) { return((int)Errors.ROLE_WRONG); } e = result; return(1); }
/// <summary> /// Cập nhật sản phẩm cho thuê /// </summary> /// <param name="Id"></param> /// <returns></returns> public ActionResult UpdateLeaseProduct(int Id) { ViewBag.ActionSubMenu = "Lease"; // Kiểm tra quyền đăng bài Entities.Item role = new Entities.Item(); int result = CheckRolePost(ref role); if (result < 0) { return(Redirect(result)); } Models.ProductModel model = new Models.ProductModel(); if (Id > 0) { Entities.Product e = productService.GetById(Id); model.MapFrom(e, ref model); } else { // set default. model.SellStartDate = DateTime.Now; model.SellEndDate = DateTime.Now.AddMonths(1); model.UserId = int.Parse(CookieHelper.Get(AdminConfigs.COOKIES_USER_ID)); model.UserName = CookieHelper.Get(AdminConfigs.COOKIES_USERNAME); } LoadModel(ref model); // Add list product List <Entities.Product> lstEntity = productService.List(); ViewBag.ListProduct = lstEntity; ViewBag.NumberItem = lstEntity.Count; ViewBag.ActionForm = "UpdateLeaseProduct"; ViewBag.SubmitValue = Id > 0 ? AdminConfigs.BUTTON_UPDATE : AdminConfigs.BUTTON_POST_NEW; return(PartialView("Index", model)); }
static void InsertSingleItemEntityLite(int i) { using (var ds = new NorthwindDataService()) { var item = new Entities.Item { Field1 = "Field 1." + i.ToString(), Field2 = "Field 2." + i.ToString(), Field3 = "Field 3." + i.ToString(), Field4 = "Field 4." + i.ToString() }; ds.ItemRepository.Insert(item); } }
public ActionResult UpdateLeaseProduct(int id, Models.ProductModel model, int[] ListRegionNeighbor) { ViewBag.ActionSubMenu = "Lease"; bool isSuccess = false; int newId = 0; // Kiểm tra quyền đăng bài Entities.Item role = new Entities.Item(); int roleId = CheckRolePost(ref role); if (roleId < 0) { Logs.LogWrite("UpdateLeaseProduct Kiểm tra quyền đăng"); return(Redirect(roleId)); } if (ModelState.IsValid) { Entities.Product e = new Entities.Product(); model.Id = id; model.Transaction_Type = (int)Enums.TransactionType.CHO_THUE; // nhà cho thuê model.UserId = int.Parse(CookieHelper.Get(AdminConfigs.COOKIES_USER_ID)); // Chuyển tiền thành triệu. model.StandardCost = StringHelperExtension.MoneyExchange(model.StandardCost); model.MapFrom(model, ref e); if (id <= 0) { e.UpdateBy = e.UserId; // Lấy thông tin username e.UserName = CookieHelper.Get(AdminConfigs.COOKIES_USERNAME); // Lấy thông tin role. e.RoleId = role.Id; e.RoleText = role.Text; } int result = 0; result = productService.Save(e); if (result < 0) { ViewBag.Message = AdminConfigs.MESSAGE_UPDATE_ERROR; ViewBag.AlertClass = AdminConfigs.CLASS_ALERT_DANGER; TempData[AdminConfigs.TEMP_MESSAGE] = AdminConfigs.MESSAGE_UPDATE_ERROR; } else { newId = result; #region Xử lý thêm ảnh vào database Models.ImageConfig[] arrImg = GetAllFileInfo(id, ImageType.PRODUCT_TEMP, e.UserName); if (arrImg.Count() > 0) { string sourceFolder = AdminConfigs.PHYSICAL_PATH + CookieHelper.Get(AdminConfigs.COOKIES_USERNAME).ToLower() + AdminConfigs.DIRSEPARATOR + AdminConfigs.FOLDER_PRODUCT_TEMPS; string targetFolder = AdminConfigs.PHYSICAL_PATH + CookieHelper.Get(AdminConfigs.COOKIES_USERNAME).ToLower() + AdminConfigs.DIRSEPARATOR + AdminConfigs.FOLDER_PRODUCTS; string urlImg = AdminConfigs.IMAGE_PATH + CookieHelper.Get(AdminConfigs.COOKIES_USERNAME).ToLower() + AdminConfigs.ALTDIRECTORYSEPARATORCHAR + AdminConfigs.FOLDER_PRODUCTS + AdminConfigs.ALTDIRECTORYSEPARATORCHAR; string urlImgTemp = AdminConfigs.IMAGE_PATH + CookieHelper.Get(AdminConfigs.COOKIES_USERNAME).ToLower() + AdminConfigs.ALTDIRECTORYSEPARATORCHAR + AdminConfigs.FOLDER_PRODUCT_TEMPS + AdminConfigs.ALTDIRECTORYSEPARATORCHAR; try { // Cập nhật avatar productService.UpdateAvatar(result, arrImg[0].caption, urlImg + AdminConfigs.AVATAR_WIDTH + "_" + AdminConfigs.AVATAR_HEIGHT + AdminConfigs.ALTDIRECTORYSEPARATORCHAR); // Cập nhật tất cả ảnh vào DB Entities.ProductImage pi; foreach (Models.ImageConfig img in arrImg) { pi = new Entities.ProductImage(); pi.ProductId = result; pi.Text = img.caption; pi.Size = img.size; pi.ImageUrl = urlImg; pi.DateUpload = System.DateTime.Now; productService.Insert(pi); FileHelper.CropImage(Server.MapPath(Url.Content(urlImgTemp + img.caption))); } // Xử lý chuyển ảnh từ folder temp sang folder product. FileHelper.MoveFile(sourceFolder, targetFolder); } catch { } } #endregion #region Xử lý cập nhật danh sách Product - Region // Cập nhật vùng cố định. Entities.Product_Region pr; if (id == 0) { pr = new Entities.Product_Region(); // Insert pr.ProductId = result; pr.RegionId = model.regionFixedId; pr.Fixed = true; pr.Status = true; productService.Insert(pr); if (ListRegionNeighbor != null) { foreach (int regionId in ListRegionNeighbor) { pr = new Entities.Product_Region(); pr.ProductId = result; pr.RegionId = regionId; pr.Fixed = false; pr.Status = true; productService.Insert(pr); } } } else { // Update vùng cố định. int regionFixedDB = productService.GetRegionFixed(id); // Nếu đã tồn tại thì kiểm tra sự trùng khớp với regionFixedId if (regionFixedDB > 0) { // Nếu có sự khác thì cập nhật. if (regionFixedDB != model.regionFixedId) { pr = productService.GetProductRegion(id, regionFixedDB); pr.RegionId = model.regionFixedId; productService.Update(pr); } } // Cập nhật vùng lân cận. // 1. Lấy danh sách vùng lân cận theo product ID // 2. So sánh vùng lân cận đã lưu trong DB với vùng lân cận mới // + Nếu trong DB có mà danh sách mới không có thì update Status--> false. // + Nếu trong DB không có thì thêm mới. var listNeighborRegionDB = productService.ListNeighborRegion(id); if (listNeighborRegionDB != null) { foreach (Entities.Item item in listNeighborRegionDB) { if (!ListRegionNeighbor.Contains(item.Id)) { // Update status. pr = productService.GetProductRegion(id, item.Id); pr.Status = false; productService.Update(pr); } } foreach (int regionId in ListRegionNeighbor) { if (!listNeighborRegionDB.Exists(x => x.Id == regionId)) { // Add new pr = new Entities.Product_Region(); pr.ProductId = id; pr.RegionId = regionId; pr.Fixed = false; pr.Status = true; productService.Insert(pr); } else { // Update if status = false. pr = productService.GetProductRegion(id, regionId); if (pr.Status == false) { pr.Status = true; productService.Update(pr); } } } } else { foreach (int regionId in ListRegionNeighbor) { // Add new pr = new Entities.Product_Region(); pr.ProductId = id; pr.RegionId = regionId; pr.Fixed = false; pr.Status = true; productService.Insert(pr); } } } #endregion #region Xử lý gửi mail cho môi giới // Lấy thông tin host. Uri uri = Request.Url; string urlHost = uri.GetLeftPart(UriPartial.Authority); // Link sản phẩm. string link = "<a href='" + urlHost + "/" + AdminConfigs.FRIENDLY_LINK_PRODUCT_DETAIL.ToFriendlyUrl(result, e.Text.ToAlias()) + "'>" + e.Text + "</a>"; ArticleService articleService = new ArticleService(); Entities.Article article = new Entities.Article(); // Danh sách những email cần phải gửi thông tin. List <string> ListEmail = new List <string>(); // Lấy form mail từ bài viết article = articleService.GetByAlias("[email_thong_bao_san_pham_moi]"); // Xử lý các tham số trong mail. // Thay tên người bán article.Body = article.Body.Replace("[user]", e.UserName); // Thay tên sản phẩm article.Title = article.Title.Replace("[product]", e.Text); article.Body = article.Body.Replace("[product]", link); // Lấy danh sách email của các môi giới ListEmail = productService.ListEmailAgency(result); BusinessLayer.Helpers.MailHelper.MailArticle(article, ListEmail); #endregion TempData[AdminConfigs.TEMP_MESSAGE] = AdminConfigs.MESSAGE_UPDATE_SUCCESS; isSuccess = true; } } else { var errors = ModelState.Select(x => x.Value.Errors) .Where(y => y.Count > 0) .ToList(); ViewBag.Message = AdminConfigs.MESSAGE_UPDATE_ERROR; ViewBag.AlertClass = AdminConfigs.CLASS_ALERT_DANGER; } LoadModel(ref model); ViewBag.ActionForm = "UpdateLeaseProduct"; ViewBag.SubmitValue = id > 0 ? AdminConfigs.BUTTON_UPDATE : AdminConfigs.BUTTON_ADD; if (isSuccess) { //return RedirectToAction("Index", new { type = "", page = 1 }); return(RedirectToAction("Detail", "Template1", new { area = "", Id = newId })); } else { return(PartialView("Index", model)); } }
public int Save(Entities.Item Item) { var dal = new DAL.Items(); return(dal.Save(Item)); }
public void InitProduct() { product = new Entities.Product(Entities.Enums.ProductType.Book, "Dragon Ball Wiki"); item = new Entities.Item(taxesCalculator, product, false, 40.0m); }
public async Task <IHttpActionResult> Update(Entities.Item Item) { var bll = new BLL.Items(); return(Ok <int>(await bll.SaveAsync(Item))); }
public void InitProduct() { product = new Entities.Product(Entities.Enums.ProductType.Perfume, "Goku Spirit Ball Limited Edition"); item = new Entities.Item(taxesCalculator, product, true, 15.0m); }
static void InsertMultipleItems(int itemCount) { ds.BeginTransaction(); for (int i = 1; i < itemCount; i++) { var item = new Entities.Item { Field1 = "Field 1." + i.ToString(), Field2 = "Field 2." + i.ToString(), Field3 = "Field 3." + i.ToString(), Field4 = "Field 4." + i.ToString() }; ds.ItemRepository.Insert(item); } ds.Commit(); }