public async Task AddAndUpdateTest() { var message = new Message() { FullName = "full name", Email = "*****@*****.**", Subject = "message subject", Text = "message content" }; await _messageRepo.Add(message); Assert.IsNotNull(message.Id); // fetch it back var alreadyAddedMessage = _messageRepo.Where(c => c.FullName == "full name").Single(); Assert.IsNotNull(alreadyAddedMessage); Assert.AreEqual(alreadyAddedMessage.FullName, message.FullName); Assert.AreEqual(alreadyAddedMessage.Subject, message.Subject); Assert.AreEqual(alreadyAddedMessage.Email, message.Email); Assert.AreEqual(alreadyAddedMessage.Text, message.Text); var messageNewName = "New name for message"; alreadyAddedMessage.FullName = messageNewName; await _messageRepo.Update(alreadyAddedMessage); var updatedMessage = await _messageRepo.GetById(alreadyAddedMessage.Id); Assert.IsNotNull(updatedMessage); Assert.AreEqual(updatedMessage.FullName, messageNewName); }
public async Task AddAndUpdateTest() { var slider = new Slider() { ImageSrc = "image source", ImageAlt = "image alt", DisplayOrder = 10, IsActive = true }; await _sliderRepo.Add(slider); Assert.IsNotNull(slider.Id); // fetch it back var alreadyAddedSlider = _sliderRepo.Where(c => c.ImageSrc == "image source").Single(); Assert.IsNotNull(alreadyAddedSlider); Assert.AreEqual(alreadyAddedSlider.ImageSrc, slider.ImageSrc); Assert.AreEqual(alreadyAddedSlider.ImageAlt, slider.ImageAlt); Assert.AreEqual(alreadyAddedSlider.DisplayOrder, slider.DisplayOrder); Assert.AreEqual(alreadyAddedSlider.IsActive, slider.IsActive); var ImageSrcNewName = "New source for image"; alreadyAddedSlider.ImageSrc = ImageSrcNewName; await _sliderRepo.Update(alreadyAddedSlider); var updatedMessage = await _sliderRepo.GetById(alreadyAddedSlider.Id); Assert.IsNotNull(updatedMessage); Assert.AreEqual(updatedMessage.ImageSrc, ImageSrcNewName); }
public async Task AddAndUpdateTest() { var label = new Label() { LabelId = 100, LabelName = "label name", Text = "label text", LanguageId = 12 }; await _labelRepo.Add(label); Assert.IsNotNull(label.Id); // fetch it back var alreadyAddedLabel = _labelRepo.Where(c => c.LabelName == "label name").Single(); Assert.IsNotNull(alreadyAddedLabel); Assert.AreEqual(alreadyAddedLabel.LabelId, label.LabelId); Assert.AreEqual(alreadyAddedLabel.Text, label.Text); Assert.AreEqual(alreadyAddedLabel.LanguageId, label.LanguageId); var labelNewName = "New name for image"; alreadyAddedLabel.LabelName = labelNewName; await _labelRepo.Update(alreadyAddedLabel); var updatedImage = await _labelRepo.GetById(alreadyAddedLabel.Id); Assert.IsNotNull(updatedImage); Assert.AreEqual(updatedImage.LabelName, labelNewName); }
public async Task AddAndUpdateTest() { var setting = new Setting() { ImageLocation = "Image Location", Type = 100 }; await _settingsRepo.Add(setting); Assert.IsNotNull(setting.Id); // fetch it back var alreadyAddedSetting = _settingsRepo.Where(c => c.ImageLocation == "Image Location").Single(); Assert.IsNotNull(alreadyAddedSetting); Assert.AreEqual(alreadyAddedSetting.ImageLocation, setting.ImageLocation); Assert.AreEqual(alreadyAddedSetting.Type, setting.Type); var messageNewName = "New image location"; alreadyAddedSetting.ImageLocation = messageNewName; await _settingsRepo.Update(alreadyAddedSetting); var updatedMessage = await _settingsRepo.GetById(alreadyAddedSetting.Id); Assert.IsNotNull(updatedMessage); Assert.AreEqual(updatedMessage.ImageLocation, messageNewName); }
public async Task AddAndUpdateTest() { var image = new Image() { Name = "image name", Link = "image link" }; await _imageRepo.Add(image); Assert.IsNotNull(image.Id); // fetch it back var alreadyAddedImage = _imageRepo.Where(c => c.Name == "image name").Single(); Assert.IsNotNull(alreadyAddedImage); Assert.AreEqual(alreadyAddedImage.Name, image.Name); Assert.AreEqual(alreadyAddedImage.Link, image.Link); var imageNewName = "New name for image"; alreadyAddedImage.Name = imageNewName; await _imageRepo.Update(alreadyAddedImage); var updatedImage = await _imageRepo.GetById(alreadyAddedImage.Id); Assert.IsNotNull(updatedImage); Assert.AreEqual(updatedImage.Name, imageNewName); }
public void AddAndUpdateTest() { var artist = new Artist() { ArtistId = 1000, FirstName = "New Artist first name", MiddleName = "New Artist middle name", LastName = "New Artist last name", DisplayName = "New Artist display", Text = "About the artist", LanguageId = 1, Language = "en", IsActive = true, ImageLink = "ArtistImageLing", DisplayOrder = 1, Hash = "newartsithash" }; _artistRepo.Add(artist); Assert.IsNotNull(artist.Id); // fetch it back var alreadyAddedArtist = _artistRepo.Where(c => c.FirstName == "New Artist first name").Single(); Assert.IsNotNull(alreadyAddedArtist); Assert.AreEqual(alreadyAddedArtist.FirstName, artist.FirstName); Assert.AreEqual(alreadyAddedArtist.LastName, artist.LastName); Assert.AreEqual(alreadyAddedArtist.MiddleName, artist.MiddleName); Assert.AreEqual(alreadyAddedArtist.ArtistId, artist.ArtistId); Assert.AreEqual(alreadyAddedArtist.DisplayName, artist.DisplayName); Assert.AreEqual(alreadyAddedArtist.DisplayOrder, artist.DisplayOrder); Assert.AreEqual(alreadyAddedArtist.IsActive, artist.IsActive); Assert.AreEqual(alreadyAddedArtist.Language, artist.Language); Assert.AreEqual(alreadyAddedArtist.LanguageId, artist.LanguageId); Assert.AreEqual(alreadyAddedArtist.ImageLink, artist.ImageLink); Assert.AreEqual(alreadyAddedArtist.Hash, artist.Hash); Assert.AreEqual(alreadyAddedArtist.Text, artist.Text); var artistNewName = "New name for artist"; alreadyAddedArtist.FirstName = artistNewName; _artistRepo.Update(alreadyAddedArtist); _artistRepo.GetById(alreadyAddedArtist.Id).ContinueWith((task) => { var updatedArtist = task.Result; Assert.IsNotNull(updatedArtist); Assert.AreEqual(updatedArtist.FirstName, artistNewName); }); }
public ObjectResult Put([FromBody] Language language) { //var command = new AddNewLanguage { NewLanguage = language }; //BusConfig.Bus.Send(BusConfig.BusEndpointName, command); _languageRepo.Add(language); return(new HttpOkObjectResult("Success")); }
public async Task AddLog(Log log) { var addLog = bool.Parse(ConfigurationManager.AppSettings["AddLog"]); if (addLog) { await _repository.Add(log); } }
public async Task AddAndUpdateTest() { var social = new Social() { LrgImage = "large image", Link = "link to social", Name = "social name", MidImage = "mid image", Title = "social title", Alt = "F" }; await _socialRepo.Add(social); Assert.IsNotNull(social.Id); // fetch it back var alreadyAddedSocial = _socialRepo.Where(c => c.Name == "social name").Single(); Assert.IsNotNull(alreadyAddedSocial); Assert.AreEqual(alreadyAddedSocial.LrgImage, social.LrgImage); Assert.AreEqual(alreadyAddedSocial.Link, social.Link); Assert.AreEqual(alreadyAddedSocial.MidImage, social.MidImage); Assert.AreEqual(alreadyAddedSocial.Name, social.Name); Assert.AreEqual(alreadyAddedSocial.Title, social.Title); Assert.AreEqual(alreadyAddedSocial.Alt, social.Alt); var socialNewName = "New name for social"; alreadyAddedSocial.Name = socialNewName; await _socialRepo.Update(alreadyAddedSocial); var updatedSocial = await _socialRepo.GetById(alreadyAddedSocial.Id); Assert.IsNotNull(updatedSocial); Assert.AreEqual(updatedSocial.Name, socialNewName); }
private async Task SaveTicketGroups(List<List<Seat>> groups, int bteId, int ticketsNumber, string url) { var ticketGroups = new List<TicketGroup>(); foreach (var group in groups) { var accessibility = new List<string>(); var inventoryTypes = new List<string>(); foreach (var seat in group) { accessibility.AddRange(seat.Accessibility); inventoryTypes.AddRange(seat.InventoryTypes); } accessibility = accessibility.Distinct().OrderBy(x => x).ToList(); inventoryTypes = inventoryTypes.Distinct().OrderBy(x => x).ToList(); var firstSeat = group.First(); var ticketGroup = new TicketGroup() { //BteId = bteId, SeatQty = group.Count, ObstructedView = false, StartSeatNumber = firstSeat.Name, EndSeatNumber = group.Last().Name, Row = firstSeat.Row, Section = firstSeat.Section, Offers = firstSeat.Offers.Distinct().ToList(), SeatTypes = firstSeat.SeatTypes, Accessibility = accessibility, InventoryTypes = inventoryTypes, }; ticketGroups.Add(ticketGroup); } var model = new TicketGroupModel { Groups = ticketGroups, DatePulled = DateTime.UtcNow, //BteId = bteId, TicketsNumber = ticketsNumber, Result = SiteResponse.Success, Url = url }; await _repository.Add(model); }
protected async void UpConnectBusinessMessage() { var connectBusinessQr = new Resource() { ResourceName = "BusinessLinkQr", ResourceValue = "{0} is connected to your business now" }; await _resourceRepository.Add(connectBusinessQr); var businessLinkEmail = new Resource() { ResourceName = "BusinessLinkEmail", ResourceValue = "{0} has sent you business link request" }; await _resourceRepository.Add(businessLinkEmail); var businessJoinEmail = new Resource() { ResourceName = "BusinessJoinEmail", ResourceValue = "{0} has accepted your link request" }; await _resourceRepository.Add(businessJoinEmail); }
private async void LogRequest(ServiceLog requestLog, string clientId, ResponseCodeType responseCode, Stopwatch requestWatch, bool logRolling) { try { requestLog.ResponseCode = responseCode; requestWatch.Stop(); requestLog.TimeTakenMs = requestWatch.ElapsedMilliseconds; await mongoRepository.Add(requestLog, clientId, requestLog.GetType().Name, logRolling); } catch (Exception exception) { logger.LogError("Error logging service request: " + exception.Message); } }
public async Task AddAndUpdateTest() { var announcement = new Announcement() { Name = "Announcement header", IsActive = true, Text = "Announcement text", LanguageId = ObjectId.GenerateNewId().ToString() }; await _announcementRepo.Add(announcement); Assert.IsNotNull(announcement.Id); // fetch it back var alreadyAddedAnn = _announcementRepo.Where(c => c.Name == "Announcement header").Single(); Assert.IsNotNull(alreadyAddedAnn); Assert.AreEqual(alreadyAddedAnn.Name, announcement.Name); Assert.AreEqual(alreadyAddedAnn.IsActive, announcement.IsActive); Assert.AreEqual(alreadyAddedAnn.LanguageId, announcement.LanguageId); Assert.AreEqual(alreadyAddedAnn.Text, announcement.Text); var annNewName = "New name for Announcement"; alreadyAddedAnn.Name = annNewName; await _announcementRepo.Update(alreadyAddedAnn); await _announcementRepo.GetById(alreadyAddedAnn.Id).ContinueWith((task) => { var updatedArtist = task.Result; Assert.IsNotNull(updatedArtist); Assert.AreEqual(updatedArtist.Name, annNewName); }); }
public async Task AddAndUpdateTest() { var language = new Language() { Abbreviation = "language abbreviation", Name = "language name", EnName = "language en name", FlagImage = "flag image link", Locale = "en" }; await _languageRepo.Add(language); Assert.IsNotNull(language.Id); // fetch it back var alreadyAddedLanguage = _languageRepo.Where(c => c.Name == "language name").Single(); Assert.IsNotNull(alreadyAddedLanguage); Assert.AreEqual(alreadyAddedLanguage.Name, language.Name); Assert.AreEqual(alreadyAddedLanguage.Abbreviation, language.Abbreviation); Assert.AreEqual(alreadyAddedLanguage.EnName, language.EnName); Assert.AreEqual(alreadyAddedLanguage.FlagImage, language.FlagImage); Assert.AreEqual(alreadyAddedLanguage.Locale, language.Locale); var languageNewName = "New name for image"; alreadyAddedLanguage.Name = languageNewName; await _languageRepo.Update(alreadyAddedLanguage); var updatedImage = await _languageRepo.GetById(alreadyAddedLanguage.Id); Assert.IsNotNull(updatedImage); Assert.AreEqual(updatedImage.Name, languageNewName); }
public void Add(T entity) { if (GetMongo <T> .IsMongo()) { if (entity is Game && _mongoRepository.GetSingle((entity as Game).Key) != null) { _mongoRepository.MakeOutdated((entity as Game).Key); } else if (_mongoRepository.GetSingle(entity.Id.AsObjectId().ToString()) != null) { _mongoRepository.MakeOutdated(entity.Id.AsObjectId().ToString()); } } _sqlRepository.Add(entity); _logging.Add(new Logging(DateTime.UtcNow, "Add entity from Sql", typeof(T).Name, MongoRepository <TD> .GetVersion(entity))); }
public ActionResult AddOrEdit(User model) { if (!ModelState.IsValid) { return(UIHelper.Result()); } try { if (model._id == 0) { if (!CheckRepeat(model)) { Alert.Show("已有相同记录存在!", MessageBoxIcon.Warning); } else { model._id = (int)(_rep.Max(t => t._id) ?? 0) + 1; model.UserPwd = CommonHelper.GetMd5(model.UserPwd, true); _rep.Add(model); // 关闭本窗体(触发窗体的关闭事件) PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } } else { if (!(model.UserPwd.Length > 18)) { model.UserPwd = CommonHelper.GetMd5(model.UserPwd, true); } _rep.Update(t => t._id == model._id, Builders <User> .Update.Set(t => t.UserName, model.UserName) .Set(t => t.UserPwd, model.UserPwd) .Set(t => t.LoginName, model.LoginName) .Set(t => t.Remark, model.Remark)); // 关闭本窗体(触发窗体的关闭事件) PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } } catch (Exception ex) { Alert.Show(ex.Message, MessageBoxIcon.Warning); } return(UIHelper.Result()); }
public async void SaveAllResource(ResourceData data) { if (await _repository.Count() > 0) { await _repository.DeleteAll(); } var resList = data.ResourceContents.Select(a => new Resource() { ResourceValue = a.Value, ResourceName = a.Name }).ToList(); resList.Add(new Resource() { ResourceName = "BusinessLinkQr", ResourceValue = "{0} is connected to your business now" }); resList.Add(new Resource() { ResourceName = "BusinessLinkEmail", ResourceValue = "{0} has sent you business link request" }); resList.Add(new Resource() { ResourceName = "BusinessJoinEmail", ResourceValue = "{0} has accepted your link request" }); resList.Add(new Resource() { ResourceName = "AssignProjectMessage", ResourceValue = "{0} has assigned you a new project" }); resList.Add(new Resource() { ResourceName = "AssignProjectActivityMessage", ResourceValue = "{0} has assigned you a project activity." }); await _repository.Add(resList); var mongoMigrator = new Hub3cMongoMigrator(_repository); }
public ActionResult Auth(string id, int[] screen, int[] price, int range, int permission) { var auth = _repAuth.Get(t => t.UserId == int.Parse(id)); if (auth == null) { _repAuth.Add(new Auth { UserId = int.Parse(id), Values = screen, Values2 = price, Range = range, Permission = permission }); } else { _repAuth.Update(t => t.UserId == int.Parse(id), Builders <Auth> .Update.Set(t => t.Values, screen) .Set(t => t.Values2, price) .Set(t => t.Range, range) .Set(t => t.Permission, permission)); } ShowNotify("授权成功"); PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); return(UIHelper.Result()); }
public async Task <string> Add() { //创建两个不同企业ID的实体数据 var model1 = new ActionLog(); model1.CompanyId = Guid.Parse("B29BC831-A974-4114-90E2-0001E03FBCAF"); model1.ActionLogId = Guid.NewGuid(); model1.Context = "test1"; model1.CreateTime = DateTime.Now; model1.UpdateTime = DateTime.Now; var model2 = new ActionLog { CompanyId = Guid.Parse("651bbe49-a4c8-4514-babb-897dad7065e3"), ActionLogId = Guid.NewGuid(), Context = "test2", CreateTime = DateTime.Now, UpdateTime = DateTime.Now }; var list = new List <ActionLog>(); list.Add(model1); list.Add(model2); var group_list = list.GroupBy(p => p.CompanyId); var tableName = "ActionLog_" + DateTime.Now.ToString("yyyy-MM-dd"); foreach (var group in group_list) { var dbName = "ActionLog_" + group.FirstOrDefault().CompanyId.ToString(); await _IMongoRepository.Add(group.ToList(), dbName, tableName); } return("value1"); }
public ActionResult AddOrEdit(BasicData model) { if (!ModelState.IsValid) { return(UIHelper.Result()); } try { if (model._id == 0) { if (!CheckRepeat(model)) { Alert.Show("已有相同记录存在!", MessageBoxIcon.Warning); } else { _rep.Add(model); // 关闭本窗体(触发窗体的关闭事件) PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } } else { _rep.Update(t => t._id == model._id, Builders <BasicData> .Update.Set(t => t.Name, model.Name) .Set(t => t.Type, model.Type) .Set(t => t.Remark, model.Remark)); // 关闭本窗体(触发窗体的关闭事件) PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } } catch (Exception ex) { Alert.Show(ex.Message, MessageBoxIcon.Warning); } return(UIHelper.Result()); }
public ActionResult AddOrEditContacts(ServiceAlertContacts model) { if (!ModelState.IsValid) { return(UIHelper.Result()); } try { if (string.IsNullOrEmpty(model._id)) { var serviceId = Request["ServiceId"]; var primaryId = Request["PrimaryId"]; model.ServiceId = int.Parse(serviceId); model.PrimaryId = int.Parse(primaryId); _alertContacts.Add(model); // 关闭本窗体(触发窗体的关闭事件) PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } else { _alertContacts.Update(t => t._id == model._id, Builders <ServiceAlertContacts> .Update.Set(t => t.UserName, model.UserName).Set(t => t.Tel, model.Tel) .Set(t => t.Email, model.Email) .Set(t => t.WeiXin_UID, model.WeiXin_UID) .Set(t => t.DingTalk_UID, model.DingTalk_UID) .Set(t => t.AlarmType, model.AlarmType) .Set(t => t.Remark, model.Remark)); // 关闭本窗体(触发窗体的关闭事件) PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } } catch (Exception ex) { Alert.Show(ex.Message, MessageBoxIcon.Warning); } return(UIHelper.Result()); }
public ActionResult btnSubmit_Click(JArray Grid1_fields, JArray Grid1_modifiedData, int Grid1_pageIndex, int Grid1_pageSize, string id, string isLog) { if (!Grid1_modifiedData.Any()) { ShowNotify("无修改数据!"); return(UIHelper.Result()); } //var detail = _repDetail.Get(t => t._id == int.Parse(id)); //var detailIds = new List<int>(); //if (detail.IsLog) //{ // detailIds.Add(detail._id); //} //else //{ // detailIds.AddRange( // _repDetail.Find(t => t.DeviceNum == detail.DeviceNum && !t.IsLog) // .ToList() // .Select(t => t._id) // .ToList()); //} foreach (var jToken in Grid1_modifiedData) { var modifiedRow = (JObject)jToken; string status = modifiedRow.Value <string>("status"); var rowId = modifiedRow.Value <string>("id"); var rowDic = modifiedRow.Value <JObject>("values").ToObject <Dictionary <string, object> >(); if (status == "newadded") { var model = new Accessory(); foreach (var p in rowDic) { typeof(Accessory).GetProperty(p.Key).SetValue(model, p.Value); } //model.RecDetailIds = detailIds.ToArray(); if (string.IsNullOrEmpty(isLog)) { model.RecId = int.Parse(id); } else { model.RecDetailId = int.Parse(id); } _rep.Add(model); } else if (status == "modified") { foreach (var p in rowDic) { var param = Expression.Parameter(typeof(Accessory), "x"); var body = Expression.Property(param, typeof(Accessory), p.Key); var lambda = Expression.Lambda <Func <Accessory, object> >(Expression.Convert(body, typeof(object)), param); _rep.Update(t => t._id == int.Parse(rowId), Builders <Accessory> .Update.Set(lambda, p.Value)); } } else if (status == "deleted") { _rep.Delete(t => t._id == int.Parse(rowId)); } } int count; var source = _rep.QueryByPage(Grid1_pageIndex, Grid1_pageSize, out count, string.IsNullOrEmpty(isLog) ? Builders <Accessory> .Filter.Eq(t => t.RecId, int.Parse(id)) : Builders <Accessory> .Filter.Eq(t => t.RecDetailId, int.Parse(id))); var grid1 = UIHelper.Grid("Grid1"); grid1.RecordCount(count); grid1.DataSource(source, Grid1_fields); ShowNotify("数据保存成功!"); return(UIHelper.Result()); }
public void BatchTest() { var language = new Language() { Abbreviation = "language abbreviation", Name = "language name", EnName = "language en name", FlagImage = "flag image link", Locale = "en" }; _languageRepo.Add(language); var announcementList = new List <Announcement>(new Announcement[] { new Announcement() { Name = "Announcement1", Text = "group1", LanguageId = language.Id }, new Announcement() { Name = "Announcement2", Text = "group2", LanguageId = language.Id }, new Announcement() { Name = "Announcement3", Text = "group1", LanguageId = language.Id }, new Announcement() { Name = "Announcement4", Text = "group2", LanguageId = language.Id }, new Announcement() { Name = "Announcement5", Text = "group1", LanguageId = language.Id }, }); //Insert Batch _announcementRepo.Add(announcementList); var count = _announcementRepo.Count(); Assert.AreEqual(count, announcementList.Count); foreach (Announcement announcement in announcementList) { Assert.AreNotEqual(new string('0', 24), announcement.Id); } //Update Batch foreach (var announcement in announcementList) { announcement.IsActive = false; } _announcementRepo.Update(announcementList); foreach (var announcement in announcementList) { Assert.AreEqual(announcement.IsActive, false); } //Delete by criteria _announcementRepo.Delete(a => a.Text.StartsWith("group1")); var countAfterDel = _announcementRepo.Count(); Assert.AreEqual(countAfterDel, 2); }
public ActionResult AddOrEdit(ScreenRepairs model) { try { var isStatusInput = Request["Status_isUserInput"]; if (!string.IsNullOrEmpty(isStatusInput)) { model.Status = (HitchStatusEnum)Enum.Parse(typeof(HitchStatusEnum), Request["Status_text"]); } var isTypeInput = Request["HitchType_isUserInput"]; if (!string.IsNullOrEmpty(isTypeInput)) { if (bool.Parse(isTypeInput)) { model.HitchType = Request["HitchType_text"]; } } var isAccInput = Request["Accepter_isUserInput"]; var isHandInput = Request["Handler_isUserInput"]; if (!string.IsNullOrEmpty(isAccInput)) { model.Accepter = Request["Accepter_text"]; } if (!string.IsNullOrEmpty(isHandInput)) { model.Handler = Request["Handler_text"]; } //处理上传附件 var file = Request.Files["file"]; if (file != null && file.ContentLength != 0) { var fileName = file.FileName; var fileType = GetFileType(fileName); if (!ValidFileTypes.Contains(fileType)) { // 清空文件上传组件 UIHelper.FileUpload("file").Reset(); ShowNotify("无效的文件类型!"); } else { var md5 = file.InputStream.GetMd5(); var repairModel = _rep.Get(t => t.FileMd5 == md5); if (repairModel != null) { model.FileName = repairModel.FileName; model.FilePath = repairModel.FilePath; } else { var name = file.FileName; if (_rep.Get(t => t.FileName == file.FileName) != null) { name = file.FileName + "_" + Guid.NewGuid(); } var path = Server.MapPath("~/attachments"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var attachPath = Path.Combine(path, name); file.SaveAs(attachPath); model.FileName = name; model.FilePath = attachPath; } model.FileMd5 = md5; } } if (model._id == 0) { model._id = (int)(_rep.Max(t => t._id) ?? 0) + 1; _rep.Add(model); // 关闭本窗体(触发窗体的关闭事件) PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } else { _rep.Update(t => t._id == model._id, Builders <ScreenRepairs> .Update.Set(t => t.RepairsDate, model.RepairsDate) .Set(t => t.LineName, model.LineName) .Set(t => t.Station, model.Station) .Set(t => t.Owner, model.Owner) .Set(t => t.RepairsSource, model.RepairsSource) .Set(t => t.Accepter, model.Accepter) .Set(t => t.Handler, model.Handler) .Set(t => t.HitchType, model.HitchType) .Set(t => t.Status, model.Status) .Set(t => t.HitchContent, model.HitchContent) .Set(t => t.Solution, model.Solution) .Set(t => t.FileName, model.FileName) .Set(t => t.FileMd5, model.FileMd5) .Set(t => t.FilePath, model.FilePath)); // 关闭本窗体(触发窗体的关闭事件) PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } } catch (Exception ex) { Alert.Show(ex.Message, MessageBoxIcon.Warning); } return(UIHelper.Result()); }
public ActionResult UploadFile(HttpPostedFileBase file) { if (file == null || file.ContentLength == 0) { return(UIHelper.Result()); } var fileName = file.FileName; if (!ValidateFileType(fileName)) { // 清空文件上传组件 UIHelper.FileUpload("file").Reset(); ShowNotify("无效的文件类型!"); } else { var size = file.ContentLength; var md5 = CommonHelper.GetMd5(file.InputStream); var model = _file.Get(t => t.Md5 == md5); if (model != null) { ShowNotify("文件已存在"); return(UIHelper.Result()); } var path = Server.MapPath("~/upload/"); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } var filename = Path.GetFileName(file.FileName); if (filename == null) { ShowNotify("空文件名"); return(UIHelper.Result()); } var extStart = filename.LastIndexOf(".", StringComparison.Ordinal); var ext = filename.Substring(extStart); var newName = string.Format("{0}_{1}{2}", filename.Substring(0, extStart), Guid.NewGuid(), ext); try { var url = Path.Combine(path, filename); var entity = new FileEntity { Author = "", DateTime = DateTime.Now, FileName = filename, Md5 = md5, Size = size, SecondaryId = int.Parse(Request["SecondaryId"]) }; if (System.IO.File.Exists(url)) { url = Path.Combine(path, newName); entity.FileName = newName; } file.SaveAs(url); entity.Url = url; entity.Rid = (int)(_file.Max(t => t.Rid) ?? 0) + 1; _file.Add(entity); } catch (Exception ex) { ShowNotify(ex.Message, MessageBoxIcon.Warning); return(UIHelper.Result()); } // 关闭本窗体(触发窗体的关闭事件) PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference()); } return(UIHelper.Result()); }
public Album Add(Album album) { _repository.Add(album); return(album); }
public TEntity Add(TEntity entity) { return(_repository.Add(entity)); }
public Task StoreAsync(PersistedGrant grant) { _dbRepository.Add<PersistedGrant>(grant); return Task.FromResult(0); }